Page 1 of 2
How to have the memory size
Posted: Wed Apr 07, 2004 1:08 pm
by Polo
How can I have the memory size in another way than using this api command :
GlobalSize_(mem)
Because it doesn't seem to work perfectly with the new memory commands of the beta 1.89
Posted: Wed Apr 07, 2004 1:12 pm
by freedimension
Code: Select all
Procedure GetFreeRAM()
Info.MEMORYSTATUS
Info\dwLength = SizeOf(MEMORYSTATUS)
GlobalMemoryStatus_(@Info)
ProcedureReturn Info\dwAvailPhys
EndProcedure
Procedure GetTotalRAM()
Info.MEMORYSTATUS
Info\dwLength = SizeOf(MEMORYSTATUS)
GlobalMemoryStatus_(@Info)
ProcedureReturn Info\dwTotalPhys
EndProcedure
Posted: Wed Apr 07, 2004 2:42 pm
by Polo
thanks, but I'm not searching for that (I certainly forgot to tell something, sorry

).
What I want is to do that :
mem=AllocateMemory(12)
mem=ReallocateMemory(mem,16)
For example, and now :
size=functionwhichreturnthesize(mem)
size is here supposed to be 16.
And I don't want to use the Globalsize function.
Posted: Wed Apr 07, 2004 2:57 pm
by freedimension
IMHO it should be HeapSize_() as PB uses just that, a heap.
Posted: Wed Apr 07, 2004 5:02 pm
by dontmailme
Quick and Dirty.....
Code: Select all
mem=AllocateMemory(12)
mem=ReAllocateMemory(mem,16)
hndl=getprocessheap_()
Debug heapsize_(hndl,0,mem)
Posted: Wed Apr 07, 2004 5:08 pm
by freak
Yes.. very dirty, because PB doesn't use the process heap. It creates it's own.
I wonder why this works though.
Timo
Posted: Wed Apr 07, 2004 5:11 pm
by dontmailme
Maybe.... from the API doc...
The GetProcessHeap function obtains a handle to the heap of the calling process. This handle can then be used in subsequent calls to the heap functions. !!??
Posted: Wed Apr 07, 2004 5:47 pm
by Kris_a
would it be possible to use GlobalAlloc_ instead of PB's built in memory allocators?
Posted: Wed Apr 07, 2004 5:53 pm
by dontmailme
You can use any part of the API

I think 8O
Posted: Wed Apr 07, 2004 6:14 pm
by freak
Yes I know the GetProcessHeap() function. But this function returns the heap, that
Windows has created for the process. PB however creates a seperate one.
GetProcesHeap() is intended to be used if you only need a few memory blocks,
and don't want to create an extra heap for your application.
See this:
Code: Select all
Procedure PB_Heap()
!mov eax, dword [_PB_MemoryBase] ; this is the real PB memory heap
ProcedureReturn
EndProcedure
Debug GetProcessHeap_()
Debug PB_Heap()
I guess this is an undocumented feature of windows. (that you can use 2 different heap handles and both work)
But i wouldn't count on it, who knows how different windows versions handle this.
Better use the above PB_Heap() procedure.
Timo
Posted: Wed Apr 07, 2004 6:26 pm
by dontmailme
Well this produces the same end-result.......
Code: Select all
Procedure PB_Heap()
!MOV eax, dword [_PB_MemoryBase] ; this is the real PB memory heap
ProcedureReturn
EndProcedure
mem=AllocateMemory(12)
mem=ReAllocateMemory(mem,16)
PB_hndl=PB_Heap()
hndl=getprocessheap_()
Debug heapsize_(hndl,0,mem)
Debug heapsize_(PB_hndl,0,mem)
Maybe PB requests memory from Windoze, reserves some for itself..... and then allocates from that point onwards....... so we are talking about the same memory at the end of the day..... and two different ways of acessing it..... through PB's 'stack' or through API.....
??!! Maybe Fred can answer this ??
Posted: Wed Apr 07, 2004 6:48 pm
by Polo
Fred should do himself a function that return memory size, because, I don't know why, but in some cases, the api command doesn't work and return -1
Posted: Wed Apr 07, 2004 6:56 pm
by freak
Well this produces the same end-result.......
That's what i am telling you. It produces the same end result.
But this is a not documented behaviour. (of Windows), so you can't
be 100% sure of it.
Polo wrote:Fred should do himself a function that return memory size, because, I don't know why, but in some cases, the api command doesn't work and return -1
See, there you have it. It doesn't always work.
Maybe PB requests memory from Windoze, reserves some for itself..... and then allocates from that point onwards....... so we are talking about the same memory at the end of the day..... and two different ways of acessing it..... through PB's 'stack' or through API.....
Maybe you should read a little documentation on memory management... what you say makes no sense
PB's memory management is a direct wrapper for the windows API here,
there is nothing misterious going on.
It's just a M$ *feature*, nothing more.
(I'd still stick with _PB_MemoryBase though.. just to be sure)
Timo
Posted: Thu Apr 08, 2004 12:20 pm
by Polo
In fact it works every time, it's just me who is stupid

I was doing that :
mem=allocatememory(4)
pokel(mem,4)
pokel(mem+4,1)
I was using more memory than the allowed one, and it's why it was returning -1

Posted: Thu Apr 08, 2004 1:13 pm
by dontmailme
freak wrote:
Polo wrote:Fred should do himself a function that return memory size, because, I don't know why, but in some cases, the api command doesn't work and return -1
freak wrote:
See, there you have it. It doesn't always work.
It does, see polo's corrected statement
freak wrote:
Maybe you should read a little documentation on memory management... what you say makes no sense
I see no point, you obviously have read this and you don't understand this behaviour..... 8O
freak wrote:
PB's memory management is a direct wrapper for the windows API here,
there is nothing misterious going on.
That must be why it works then !
I think maybe Fred should comment on this as he obviously knows what he's doing
