Posted: Mon Oct 20, 2008 1:47 pm
Oops! Then I misunderstood the docs. Thanks!Trond wrote:ReAllocateMemory() also zeros the memory that is newly allocated.
Regards, Little John
http://www.purebasic.com
https://www.purebasic.fr/english/
Oops! Then I misunderstood the docs. Thanks!Trond wrote:ReAllocateMemory() also zeros the memory that is newly allocated.
Code: Select all
#HEAP_CREATE_ALIGN_16 = $00010000
#HEAP_ZERO_MEMORY = $00000008
Procedure.l MemAlloc(size.l,bZeroMem.l = #False)
If bZeroMem = #False
ProcedureReturn HeapAlloc_( GetProcessHeap_(), #HEAP_CREATE_ALIGN_16, Size );
EndIf
ProcedureReturn HeapAlloc_( GetProcessHeap_(), #HEAP_CREATE_ALIGN_16 | #HEAP_ZERO_MEMORY, Size );
EndProcedure
Procedure MemFree(*p)
If *p <> #Null
HeapFree_( GetProcessHeap_(), 0, *p);
EndIf
EndProcedure
Global *pixels = #Null
Global count.l,st.l,et.l
#COUNT_LOOP = 500
OpenConsole()
st = ElapsedMilliseconds()
for count = 0 to #COUNT_LOOP
*pixels = AllocateMemory(256000) ;128*128*24 bit Image
;do something
FreeMEmory(*pixels)
next
et = ElapsedMilliseconds()
PrintN("AllocateMemory : "+Str(et-st))
st = ElapsedMilliseconds()
for count = 0 to #COUNT_LOOP
*pixels = MemAlloc(256000) ;128*128*24 bit Image
;do something
MemFree(*pixels)
next
et = ElapsedMilliseconds()
PrintN("MemAlloc : "+Str(et-st))
Repeat : until InKey()
CloseConsole()
end
31 millisecondsHotteHC wrote:@ts-soft
I repeated the allocating 500 times.
poke and peek a slow, better use pointer, copymemory or othersAND51 wrote: If you poke strings with PokeS()
Hi ts-soft, i have read that from you several times, and from Trond too, but have you tried if there is a speed difference with the use of Peek-Poke and the use of direct pointer assignations? Just disassemble it and comparets-soft wrote:poke and peek a slow, better use pointer, copymemory or othersAND51 wrote: If you poke strings with PokeS()
Psychophanta wrote:Hi ts-soft, i have read that from you several times, and from Trond too, but have you tried if there is a speed difference with the use of Peek-Poke and the use of direct pointer assignations? Just disassemble it and compare
Code: Select all
*Mem.byte = AllocateMemory(200000000)
t1 = ElapsedMilliseconds()
If *Mem
For I = 0 To 199999999
PokeB(*Mem + I, I)
Next
EndIf
t2 = ElapsedMilliseconds() - t1
t3 = ElapsedMilliseconds()
If *Mem
For I = 0 To 199999999
*Mem\b = I
*Mem + SizeOf(byte)
Next
EndIf
t4 = ElapsedMilliseconds() - t3
MessageRequester("Time:", "Poke: " + Str(t2) + #LF$ + "Pointer: " + Str(t4))
I got:ts-soft wrote:Psychophanta wrote:Hi ts-soft, i have read that from you several times, and from Trond too, but have you tried if there is a speed difference with the use of Peek-Poke and the use of direct pointer assignations? Just disassemble it and compareCode: Select all
*Mem.byte = AllocateMemory(200000000) t1 = ElapsedMilliseconds() If *Mem For I = 0 To 199999999 PokeB(*Mem + I, I) Next EndIf t2 = ElapsedMilliseconds() - t1 t3 = ElapsedMilliseconds() If *Mem For I = 0 To 199999999 *Mem\b = I *Mem + SizeOf(byte) Next EndIf t4 = ElapsedMilliseconds() - t3 MessageRequester("Time:", "Poke: " + Str(t2) + #LF$ + "Pointer: " + Str(t4))
Please test it without DebuggerPsychophanta wrote: I got:
Poke: 9578
Pointer: 14531
I did it without debugger!ts-soft wrote:Please test it without Debugger
MessageRequester wrote:---------------------------
Time:
---------------------------
Poke: 1141
Pointer: 812
---------------------------
OK
---------------------------