POV-Ray : Newsgroups : povray.programming : pov_io_base question Server Time
21 Jul 2024 08:20:13 EDT (-0400)
  pov_io_base question (Message 1 to 4 of 4)  
From: ABX
Subject: pov_io_base question
Date: 7 Oct 2002 04:36:10
Message: <nih2quouobesergu3qtvmmithvvjskjfr2@4ax.com>
Working on MPEG port I found useful to perform buffered reading: allocate
buffer and read fixed number of bytes there. The problem appear when there is
less bytes to read than specified. I have to know how much was readed. I
thought it could be useful to introduce below changes for it but since I'm not
very experienced with OOP rules and IO operations I thought I could discuss it
first. I have introduced private field 'transfered' with number of bytes
transfered to/from file and public method to get this value. I have also
changed content of read and write with reversed order of number of blocks and
size of block (I have to measure in bytes). I want to know if I do it correct
way. Perhaps direction of last transfer could be additionaly stored in sign of
transfer field. So here are my changes...

// file_pov.h

class pov_io_base
{
  public:
    ....
    inline u_int32 lasttransfer (void) { return (transfer) ; }

  protected:
    ....
    u_int32 transfer;
} ;

// file_pov.cpp

pov_io_base::pov_io_base (u_int32 dir, u_int32 type)
{
    ....
    transfer = 0;
}

pov_io_base& pov_io_base::read (void *buffer, u_int32 count)
{
  if (!fail && count > 0)
  {
    transfer = fread (buffer, 1, count, f);
    fail = ( transfer > count ) ;
  }
  else
    transfer = 0;

  return (*this) ;
}

pov_io_base& pov_io_base::write (void *buffer, u_int32 count)
{
  if (!fail && count > 0)
  {
    transfer = fwrite (buffer, 1, count, f);
    fail = ( transfer > count ) ;
  }
  else
    transfer = 0;

  return (*this) ;
}

ABX


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: pov_io_base question
Date: 7 Oct 2002 04:53:32
Message: <3da14b8c@news.povray.org>
In article <nih2quouobesergu3qtvmmithvvjskjfr2@4ax.com> , ABX 
<abx### [at] abxartpl>  wrote:

> Working on MPEG port I found useful to perform buffered reading: allocate
> buffer and read fixed number of bytes there. The problem appear when there is
> less bytes to read than specified.

If you need to do that it indicates a flaw in your reading code.  Every
(reasonable) fileformat contains sufficient information to determine how
much information is in the file, and you should just never read over the end
of a file.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: ABX
Subject: Re: pov_io_base question
Date: 7 Oct 2002 05:22:49
Message: <e1k2qusklku3cvqp08gljdoo4jmkj5clf2@4ax.com>
On Mon, 07 Oct 2002 10:53:30 +0200, "Thorsten Froehlich" <tho### [at] trfde>
wrote:
> > Working on MPEG port I found useful to perform buffered reading: allocate
> > buffer and read fixed number of bytes there. The problem appear when there is
> > less bytes to read than specified.
>
> If you need to do that it indicates a flaw in your reading code.

That's not my code. I have found more difficoult limitations in libmpeg2
library I have to fix. For example the size of the buffer I had to set was...
1 byte :-)

> Every
> (reasonable) fileformat contains sufficient information to determine how
> much information is in the file

I agree, but then... what about ascii format, in particular POV scenes ;-)

ABX


Post a reply to this message

From: Warp
Subject: Re: pov_io_base question
Date: 7 Oct 2002 10:21:17
Message: <3da1985d@news.povray.org>
ABX <abx### [at] abxartpl> wrote:
> Working on MPEG port I found useful to perform buffered reading

  Usually the C(++) compiler and even the OS (and sometimes even the
hardware itself!) will do buffered reading, so from the point of view
of performance you are most probably just replicating the work which is
already done by the underlying system.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.