Re: Reallocate() -- is this safe?
- Posted by Robert Craig <rds at RapidEuphoria.com> Oct 13, 2002
- 366 views
Andy Serpa writes: > If the new block is bigger we will be copying stuff beyond > what was in the original block -- might we run up against > the "edge" of available memory? Is that possible, > and what will happen? Yes, it's possible, and you'll get a machine-level exception in that case. > If it is not safe, is there a way to tell how big the > original block was without keeping explicit track > at allocate()-time? Every C compiler uses a different implementation of malloc(). Most, but not all, malloc's store the length of the block, or something similar, in the 4 bytes preceeding the address returned by malloc(). I think Watcom's malloc (ex, exw) stores the length of the block plus 5, so Euphoria's allocate() will currently do the same on DOS and Windows, but I don't guarantee that will always be the case. For portability, you'd be well advised to allocate an extra 4 bytes, and store the length yourself, or keep track of the length in some variable. > I don't suppose there is a way to call realloc() > directly with some undocumented machine_func()? No. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com