Page 2 of 3

Posted: Mon Oct 20, 2008 1:47 pm
by Little John
Trond wrote:ReAllocateMemory() also zeros the memory that is newly allocated.
Oops! Then I misunderstood the docs. Thanks!

Regards, Little John

Posted: Mon Oct 20, 2008 2:53 pm
by HotteHC
@ts-soft

I repeated the allocating 500 times.

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

Posted: Mon Oct 20, 2008 10:29 pm
by AND51
+1


If this really increases speed, I would also agree to this idea!

If you poke strings with PokeS(), there will be appended a null automatically; so in most cases there are no safety problems. But even if so - the programer should do what he wants to do.

Posted: Mon Oct 20, 2008 10:34 pm
by ts-soft
HotteHC wrote:@ts-soft

I repeated the allocating 500 times.
31 milliseconds :mrgreen: , and i never allocate memory 500x in one program.
Better optimize your program and don't allocate 500x :wink:
31 milliseconds is not the time to smoke a cigarete :)

Posted: Mon Oct 20, 2008 10:36 pm
by ts-soft
AND51 wrote: If you poke strings with PokeS()
poke and peek a slow, better use pointer, copymemory or others :wink:

Posted: Mon Oct 20, 2008 11:23 pm
by Deeem2031
There is an advantage at no costs so there's no reason to refuse to implement this. And btw. normaly I never need the memory to be zeroed - there are only very rare cases were this is usefull and I guess thats true for most projects.

Posted: Tue Oct 21, 2008 4:13 pm
by HotteHC
@TS-Soft

On my Laptop the Results are

-AllocateMemory : 141 ms
-MemAlloc : 0 ms !!!

And to loop this 500 times was only for Testing but I m working on
a Bitmap-Lib/2D-Engine and there I have to use many Memory allocations.

For example.
For now I'm able to load an BMP-Image with my Method realy extrem faster then with the PB-Intenals ImageLoaders.
With AllocateMemory it's equal in speed.

Posted: Tue Oct 21, 2008 4:30 pm
by ts-soft
With allocation of 25600000 bytes in your code, AllocateMemory is faster :mrgreen:
Okay, i think is a feature for slow machines, in most programs make this
no difference.

Posted: Tue Oct 21, 2008 4:37 pm
by HotteHC
Youre right.

It's strange but the big Speed-Difference is in most Times when i Allocate
an Image of 128*128*24 bit which needs 256000 bytes in Memory.

Posted: Tue Oct 21, 2008 7:42 pm
by Psychophanta
ts-soft wrote:
AND51 wrote: If you poke strings with PokeS()
poke and peek a slow, better use pointer, copymemory or others :wink:
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 :)

Posted: Tue Oct 21, 2008 8:15 pm
by ts-soft
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))

Posted: Tue Oct 21, 2008 8:49 pm
by Psychophanta
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 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:
Poke: 9578
Pointer: 14531
:wink:

Posted: Tue Oct 21, 2008 8:58 pm
by ts-soft
Psychophanta wrote: I got:
Poke: 9578
Pointer: 14531
:wink:
Please test it without Debugger :wink:

Posted: Tue Oct 21, 2008 8:59 pm
by Psychophanta
ts-soft wrote:Please test it without Debugger :wink:
I did it without debugger!
What are your results?

Posted: Tue Oct 21, 2008 9:01 pm
by ts-soft
MessageRequester wrote:---------------------------
Time:
---------------------------
Poke: 1141
Pointer: 812
---------------------------
OK
---------------------------