[Implemented] AllocateMemory without clearing

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I guess that the issue is the amount of ram: i have 512MB, and the first time i executed your code, the computer flashed the HDled a lot (looks like it wrote on the HD virtual-mem), but the next times i executed it i get about this:
Poke: 1641
Pointer: 1312
:roll:
Anyway, the difference is not so big to take it so seriously.
Do it like this:

Code: Select all

*Mem.long = AllocateMemory(200000000) 
*m=*Mem
t1 = ElapsedMilliseconds() 
If *Mem 
  For I = 0 To 199999990
    PokeL(*Mem, I)
    *Mem + SizeOf(byte)
  Next 
EndIf 
t2 = ElapsedMilliseconds() - t1 
*Mem=*m
t3 = ElapsedMilliseconds() 
If *Mem 
  For I = 0 To 199999990 
    *Mem\l = I 
    *Mem + SizeOf(byte)
  Next 
EndIf 
t4 = ElapsedMilliseconds() - t3 

MessageRequester("Time:", "Poke: " + Str(t2) + #LF$ + "Pointer: " + Str(t4))
It is more realistic. I get:
Poke: 1656
Pointer: 1500
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

I have the same results, pointers ~30% faster
My PC has 4 GB RAM on Vista64, so i think the result is real
The testcode is not optimized for pointer, it's only 1:1 translation from Poke
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Here 1500/1656 = 0.9057... so then lets say that pointers ~10% faster.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

In a real application, you compare and write to memory, direct read and
write in the mem is more than 30% faster :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

ts-soft wrote:In a real application, you compare and write to memory, direct read and
write in the mem is more than 30% faster :wink:
Mmh.. looking at the disassembled code, i doubt it. :? :)
However i always use pointers and i also suggest its use, don't forget. :wink: I just have good remembers of Poke and Peek 8)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Avoiding a call is always a good idea, as on some processors it can have more speed penalities.
alokdube
Enthusiast
Enthusiast
Posts: 148
Joined: Fri Nov 02, 2007 10:55 am
Location: India
Contact:

Post by alokdube »

umm i think when calloc is called in unix it does the same stuff
from the man page,

The calloc() function allocates space for an array of nelem
elements of size elsize. The space is initialized to zeros

If fred develops in C, he is using calloc internally I guess?

http://c.ittoolbox.com/groups/technical ... oc-1532354
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

alokdube wrote:umm i think when calloc is called in unix it does the same stuff from the man page,
There is also malloc, which does not initialise the data.

But there a simple enough way to check. Create an executable with only the AllocateMemory() and FreeMemory() commands and then look at what functions are imported from what DLL. The C runtime is not used for this :)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Post Reply