News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Allocating a large array

Started by CooPs, June 01, 2006, 02:32:42 PM

Previous topic - Next topic

Sarel

I did it this way. [PrimeCount equ 10000001]

invoke GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, ((4 * PrimeCount) + 16) ;DWords for hex values
mov ptrPrimeArray,eax
invoke GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, (24 * PrimeCount) ;Bytes for text values
mov ptrBuff1,eax

invoke GetTickCount
mov TickCount1,eax
call GetPrimes           ;Get all the prime numbers in dword format
invoke GetTickCount
mov TickCount2,eax
call WriteBuff1          ;Convert the dword values from hex to text and add the number for the prime starting at 1
invoke GetTickCount
mov TickCount3,eax
mov edx,0
mov eax,TickCount2
sub eax,TickCount1
PrintDec eax,"Find primes time" ;The time taken to find the dword values
mov edx,0
mov eax,TickCount3
sub eax,TickCount2
PrintDec eax,"Convert and Write Buf1" ;The time taken for the convertion from hex to text + the numbers

invoke GetTickCount
mov TickCount4,eax
invoke CreateFile, addr FileName1, GENERIC_READ OR GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, FILE_FLAG_RANDOM_ACCESS
mov hFile,eax
invoke WriteFile, hFile, ptrBuff1, BytesWritten2, addr BytesWritten, 0
invoke CloseHandle, hFile
invoke GetTickCount
mov TickCount5,eax
mov edx,0
mov eax,TickCount5
sub eax,TickCount4
PrintDec eax,"Create, write and close file" ;The time taken to open write and close the text file

invoke GetTickCount
mov TickCount6,eax
invoke SetWindowText,hEditInput1,ptrBuff1
invoke GetTickCount
mov TickCount7,eax
mov edx,0
mov eax,TickCount7
sub eax,TickCount6
PrintDec eax,"Write the text to the edit box" ;The time taken to get the text displayed in the edit box


And it gave me these results:
eax = 650141, Find primes time (Prime4.asm, 113)
eax = 8031, Convert and Write Buf1 (Prime4.asm, 117)
eax = 8093, Create, write and close file (Prime4.asm, 130)
eax = 605000, Write the text to the edit box (Prime4.asm, 140)

10 minutes just to get it into the window's text !
The time consuming part looks to be the part were one writes the data to the window. I doubled the primes to 20 000 000 and the text file took 26 minutes to open.

Why would this be so time consuming ?

Let us know what sort of time is involved in your program. :U

CooPs

#16
Will do as soon as I'm entierly done! ^^

Btw, couldn't find a dword to decimal function so I was like what the hell, let's write my own, and i did.

Thanks for all the tips, yeah I've decided to use GlobalAlloc as you mentioned hutch--.
One thing I find strange is that when I allocate, I get all my dwords, but the task mangager indicates that my program only uses 2 mb of memory? Shouldn't it use like 40?

EDIT: Ah found out that the memory only will be count as used when it's written to.

I need some call that will wait for all messages to be sent to my window so it can be moved and so on while my application is executing the algoritm, any ideas? :eek

asmfan

CooPs, i strongly recommend to look at the MSDN document on memory management. I read it long time ago. It basically says that if you're allocating more than 10MB of memory you should use Virtual* functions if less than then Heap* ones. Local/Global* are obsoled and only for compatibility...
Look at yourself - as i remember it was "memory management" article, where compared all these ways
Russia is a weird place

CooPs

But GlobalAlloc works just fine?

hutch--

asmfan is right that Microsoft have in the past published comments on GlobalAlloc() but since then the function is directly trandlated into NTDLL.DLL functionality that is below all of the rest so it works fine. If you were doing high speed small allocations HeapAlloc() would be a slightly better choice but with a single block allocation, Global Alloc() is well suited for that task.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

CooPs

Quote from: Sarel on June 02, 2006, 06:57:05 PM
And it gave me these results:
eax = 650141, Find primes time (Prime4.asm, 113)
eax = 8031, Convert and Write Buf1 (Prime4.asm, 117)
eax = 8093, Create, write and close file (Prime4.asm, 130)
eax = 605000, Write the text to the edit box (Prime4.asm, 140)

10 minutes just to get it into the window's text !
The time consuming part looks to be the part were one writes the data to the window. I doubled the primes to 20 000 000 and the text file took 26 minutes to open.

Why would this be so time consuming ?

Let us know what sort of time is involved in your program. :U

Yeah, I'm entirely done with my program now, and I decided to measure how long the prime calculation took and how long time it took to write the file, this is what i got:

Primes to find:
10000000
Numbers calculated:
179424691
Primes found:
10000000
Not Primes:
169424690
ms To Calculate:
491172
ms To Output Results:
16765
CPU Speed:
2.0 gHz
RAM:
1024 mb

Please tell me your CPU speed Sarel! :8)

If you're intressted in running the program yourself, feel free to download the 1.0 binary here, you can find the source here.

Notice that it suffers from random crashes now and then, and I have no idea why? Maybe memory leek, but there's no wai that memory wont get free'd.  :eek

Jimg

Antivir claims that it contains a trojan horse.  Perhaps that's the cause of the crashes  ::)

CooPs

Quote from: Jimg on June 04, 2006, 04:16:45 AM
Antivir claims that it contains a trojan horse.  Perhaps that's the cause of the crashes  ::)

Uhhuh.. I just checked the excutable in wdasm, there's no way it's infected. Thank's for scaring away people d00d.

Just download the source then...

Jimg

Sorry, just reported what I found.  I downloaded the source and recompiled, and no virus.  I have seen false positives before though....

The program ran well, same results as you, time to calc 318782, time to write 17828

[attachment deleted by admin]

Sarel

eax = 254531, Find primes time (Prime4.asm, 113)
eax = 4328, Convert and Write Buf1 (Prime4.asm, 117)
eax = 3359, Create, write and close file (Prime4.asm, 130)
eax = 380625, Write the text to the edit box (Prime4.asm, 140)
P4 3.4 GHz
1024 MB ram

Your program gave me: Time To Calc  210578 and Time To Write 43547

;------------------------------------------------------------

eax = 533096, Find primes time (Prime4.asm, 113)
eax = 7861, Convert and Write Buf1 (Prime4.asm, 117)
eax = 13900, Create, write and close file (Prime4.asm, 130)
eax = 1499396, Write the text to the edit box (Prime4.asm, 140)
P3 800 MHz overclock to 1000 MHz
448 MB ram

Your program gave me: Time To Calc  483825 and Time To Write 35121

Well, yours is faster! :green Well done.
Sorry to hear of your friends problem  :dance: You will beat his time for sure

I attached my asm file in zip format.
Enjoy all you do.



[attachment deleted by admin]