< Previous by Date Date Index Next by Date >
< Previous in Thread Thread Index Next in Thread >

Re: [reSIProcate] Compilation error in latest code


Quoting Alan Hawrylyshen <alan@xxxxxxxxxx>:

> 
> On Nov 19, 2004, at 19:37, david Butcher wrote:
> 
> >
> > Changes to Data are a cause for alarm. I made two changes recently and 
> > should
> > fess up.
> >
> > 1. Removed the memsets on the internal buffer. They were gratuitous.
> >
> Explain how they were gratuitous?  Are you now relying on linux's 
> zero-new-page property? (Unlike, but just want to confirm.)

Thanks for the vote of confidence :-)
Data does not depend on intialization of the memory. Only the terminal null 
matters, and then only if you use c_str().

> > 2. Generalized the Take/Share enum to include Borrow. Borrow is used to
> > indicate that the Data is using a writable but not owned buffer. 
> > Borrow is used
> > to indicate that the internal buffer is being used. Borrow also allows 
> > Datas to
> > be created that use stack memory rather than heap memory.
> >
> 
> I 'take' it that you also implemented the behaviour described? Any 
> issues or use notes that might affect or benefit other Data users?

Implemented. There is no legacy impact. The internals of Data are a little 
cleaner. Here is a use case:

{
  ...
  char buffer[8192];
  Data tmp(Data::Borrow, buffer, sizeof(buffer));
  // use tmp as usual -- tmp will still grow as necessary
  ...
} // buffer deallocated by scope end

I can't recommend wholesale use of this idiom, but it may be useful in inner 
loops etc. I have not tried to apply it to the stack proper -- mostly 'Shares' 
there.

david