[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: C++ exception handling question [solved]



On Mon, Nov 13, 2006 at 10:41:52AM -0700, Paul E Condon wrote:
> 
> I'm not a professional programmer, so my standards of reasonableness
> are not tempered by 'real world' experience. I use C++ to write
> simulation code for my research in biodiversity. It seems to me, from
> reading the doc.s, that realloc() should be used in the situation that
> you describe. It is possible to keep track of all places in the code
> that new objects are brought into use and check if space is available
> within the previously allocate block, and then use realloc() to expand
> the allocation if needed.

Doesn't realloc allocate new space, which means that the objects inside 
that space get moved?  Then you have to track down all the places where 
addresses of these objects are kept.

> 
> Personally, I wonder about the quality of a program design that
> requires that objects that are initialized at different times be
> stored is a single contiguous block of RAM. I think that pointers and
> references have long been known as a way to free oneself of this
> problem. But, I'm not a professional.

It happens especially when porting sotware written for other systems, 
especially software that has its own memory allocation subsystem.  For 
example, it may use compressing garbage collection, or multiple stacks.
Reserving address space separate from allocating storage within that 
space is a natural thing to do.  But I agree, malloc is not the proper 
tool for this, and I too would prefer to have a malloc that commits to 
making the storage available, and otherwise indicates that it cannot.

-- hendrik



Reply to: