RE: allocated memory enlargement
- Posted by CoJaBo <cojabo at suscom.net> Mar 27, 2004
- 501 views
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.