Re: allocated memory enlargement

new topic     » goto parent     » topic index » view thread      » older message » newer message

Tommy Carlier wrote:

>kat wrote
>  
>
>>Er,, i ever thought i'd be asking this, but if i have a block of memory 
>>allocated
>>on windows, and i want to enlarge it without changing it contents, can i?
>>How?
>>
>>Kat
>>    
>>
>If you have allocated it with the Euphoria-function allocate, you could do 
>it like this:
>
>function resize_memblock(atom old_mem, integer old_size, integer new_size)
>	atom new_mem
>	if old_size = new_size then return old_mem end if
>	new_mem = allocate(new_size)
>	if old_size < new_size then
>		mem_copy(new_mem, old_mem, old_size)
>	else
>		mem_copy(new_mem, old_mem, new_size)
>	end if
>	free(old_mem)
>	return new_mem
>end function
>
>-- Using the function:
>
>pointer = resize_memblock(pointer, size, size + 1000) -- adds 1000 bytes 
>to the memory block
>  
>
I am very pleased to see this. Not being familiar with mem_copy, I had 
wondered about a subject that Kat raised earlier regarding inserting a 
new new record into a memory buffered file. mem_copy makes it easy to 
make room for the new record. (if you are building the file in a 
specific order, alphabetical, for instance.)
Thanks, Tommy,
Allen

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu