Re: allocated memory enlargement
- Posted by Evan Marshall <1evan at sbcglobal.net> Mar 27, 2004
- 548 views
From MSDN: _expand returns a void pointer to the reallocated memory block. _expand, unlike realloc, cannot move a block to change its size. Thus, if there is sufficient memory available to expand the block without moving it, the memblock parameter to _expand is the same as the return value. If there is insufficient memory available to expand the block to the given size without moving it. The item pointed to by memblock is expanded as much as possible in its current location. _expand(void *, size) is found in libc.lib. Header file malloc.h I don't know if this helps, but here it is for what it's worth. CoJaBo wrote: > > http://click.topica.com/caab4CEb1dd66b5hhUsa/ Crazy Aaron Enterprises > > > Kat wrote: > >> >>On 26 Mar 2004, at 18:48, Allen Robnett wrote: >> >> >>>http://click.topica.com/caab4CEb1dd66b6816za/ Crazy Aaron Enterprises >>> >>> >>>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.) >> >>But the code above is not *expand* file, it's *making another new* file! >> >>Freeing the space the file occupies is definitely changing the contents >>of the >>existing space. >> >>Try to do that on a 385 megabyte system when you need to do a few >>hundred inserts real fast in a 200 meg ramdisk. The OS will page the >>files to >>disk (if you are lucky, but dos won't page to virtual ram), and your >>speed will >>be slower than if you used a disk-based system in the first place. Nix >>may >>be faster than Windows in this regard. >> >>Kat >> > > Euphoria can't resize memory directly, there is probably a .DLL somewere > that can do that(Maybe in the Win32 API). Even if there isn't you could > probably make a C .DLL. > > > > > For Topica's complete suite of email marketing solutions visit: > http://www.topica.com/?p=TEXFOOTER > >