[lazarus] mwEdit Problems
Peter Vreman
pfv at cooldown.demon.nl
Tue Oct 26 04:38:17 EDT 1999
At 04:22 26-10-99 , you wrote:
>Shane Miller wrote:
> >
> > Why do I need the current size? I should be able to do a
> > sizeof(pointer) to get the size.
>
>That will give you the size of a pointer. Not the size of the area the
>pointer is pointing to. :-\
>
>Unless you use the memory manager found in Delphi 2 and up your have
>know way of knowning how much memory is associated with a pointer to a
>memory location. You have to tell it how much memory it is associated
>with.
>
> > Actually I don't need to do that because if I am REALLOCating
> > memory, all I need to do is a freemem(pointer) getmem(pointer,newsize)
>
>This is how the current ReAllocMem works and what can be passed to it.
>As I said this is a direct match to Delphi 1.
>
>1. if P is nil and newSize is zero do nothing
>2. if P is nil and newSize is NOT zero allocate memory and clear it to 0
>3. if P is NOT nil and newSize is NOT zero a new memory block allocated
> the data is copied from the old block to the new block and the old
> block is disposed of.
>
>if P is NOT nil then currentSize must be the size used to allocate
>memory for P whether it was using AllocMem or ReAllocMem.
>
>procedure ReAllocMem(var P: Pointer; currentSize: longint; newSize:
>longint);
>
>
> > Can we get another reallocmem function added to the rtl?
>
>Unless a memory management scheme is used for AllocMem and ReAllocMem
>that will maintain a record of allocated space for memory blocks when
>using these routines you will have to pass the current size of the
>existing allocated memory.
>
>Since ReAllocMem was written I have seen some notes that indicate that
>Peter might have added some heap management that will allow you to do a
>freemem(pointer) without suppling the size of the memory block. If that
>is the case we can of course change ReAllocMem to use this form of
>FreeMem and hopefully be able to identify the size of the block for the
>copy block function.
>
>Peter is that the case????
Yes. And to get the size of a memoryblock you can use MemSize(pointer).
I still want to add the Reallocmem also to the heap manager to make a less
fragmenting function of it.
Peter
More information about the Lazarus
mailing list