Ecere SDK/eC Forums
http://ec-lang.org/community/
Print view

Does the renew operator delete the previously allocated mem?
http://ec-lang.org/community/viewtopic.php?f=1&t=63
Page 1 of 1
Author:  fedor_bel [ Wed Mar 31, 2010 8:55 am ]
Post subject:  Does the renew operator delete the previously allocated mem?

Hello,

Does the renew operator delete the previously allocated memory?

Like if some memory was allocated with new and then I call the renew operator and a completely new block of memory will be allocated, will the old block be freed?

Hopefully it will.
Author:  jerome [ Wed Mar 31, 2010 8:57 am ]
Post subject:  Re: Does the renew operator delete the previously allocated mem?

Hi fedor.

Yes the renew allocator either reuses, or frees then allocates a new block of memory.
It works similarly to the C function 'realloc'.

Typical usage:

Code: Select all

byte * mem = new byte[10];
mem = renew mem byte[20];
Use with complete peace of mind. No memory leaks.

Also note the zeroing versions:

Code: Select all

byte * mem = new0 byte[10];
mem = renew0 mem byte[20];
Which will only zero out the new portion of renew'ed memory.
All times are UTC-05:00 Page 1 of 1