fastest way to clean an array
Hi guys
Do you guys know a fastest way to clean an bidimensional array like array[200][200], without a "for" loop = 0 ??
I''ve been looking at the function ZeroMemory, but i''m afraid i don''t know how to use it.
Thanks
Bruno
Like this:
Of course, you can replace the sizeof with the size of the data type you are using.
-Jussi
"I want a place to hide, somewhere far from your side"
Edited by - Selkrank on October 6, 2000 6:55:22 AM
|
Of course, you can replace the sizeof with the size of the data type you are using.
-Jussi
"I want a place to hide, somewhere far from your side"
Edited by - Selkrank on October 6, 2000 6:55:22 AM
that code you posted shouldn''t even compile.
don''t call me picky
|
don''t call me picky

quote:
Original post by Ridcully
that code you posted shouldn''t even compile.
Yes it should. If the array was of type char, the array''s data type would be char**, and array[0]''s data type would be char*, so array[0] is right.

So, either array[0] or &(array[0][0]).
-Jussi
"What have we done?
Who killed the sun?"
and why not. its perfectly legal aint it?
my reply was to ridcully
Edited by - zedzeek on October 6, 2000 8:42:32 AM
my reply was to ridcully
Edited by - zedzeek on October 6, 2000 8:42:32 AM
You use ZeroMemory like this:
It is just like memset without the second parameter of what to set the memory to (It is actually just a macro for memset).
And for a bidimensional array is would be the same (I'm pretty sure)
-------------
cOnfuSed
Edited by - Confused on October 6, 2000 8:48:53 AM
|
It is just like memset without the second parameter of what to set the memory to (It is actually just a macro for memset).
And for a bidimensional array is would be the same (I'm pretty sure)
-------------
cOnfuSed
Edited by - Confused on October 6, 2000 8:48:53 AM
-------------cOnfuSed
October 06, 2000 01:05 PM
Fastest way? MMX, baby.
memset() is indeed a very fast function in that it doesn''t copy byte by byte (at least, the Visual C version is). It sets all dword aligned dwords (dword aligned so that two writes are not needed in order to write one dword) and then goes to work on the lead and trailing bytes.
With the FPU you can set 8 bytes at a time instead of 4 but this is only faster if the data is cache-warmed.
You can also set 8 bytes of data at a time with the MMX and this is your target if you use the same alignment strategies of memset().
memset() is indeed a very fast function in that it doesn''t copy byte by byte (at least, the Visual C version is). It sets all dword aligned dwords (dword aligned so that two writes are not needed in order to write one dword) and then goes to work on the lead and trailing bytes.
With the FPU you can set 8 bytes at a time instead of 4 but this is only faster if the data is cache-warmed.
You can also set 8 bytes of data at a time with the MMX and this is your target if you use the same alignment strategies of memset().
October 06, 2000 01:15 PM
Most implementations of memset are just a for-loop and is generally one of the _slowest_ ways to clear memory. The fastest way really depends on what system you''re talking about. Ideally you''d have some sort of vector unit that could write 4 or 8 bytes at a time, or a dma controller that can write constant values to memory. On the N64 it was faster to have the graphics system render a black quad to main memory. I guess for Intel systems, MMX would be best....
argh!
how could i overlook that?
well, must be that damn headache i''ve got at the moment. probably i shouldn''t visit the board while i am ill.
sorry anyways
rid
how could i overlook that?
well, must be that damn headache i''ve got at the moment. probably i shouldn''t visit the board while i am ill.
sorry anyways
rid
try this:
memset compiled to ASM is usually just a for loop MOVing 0 into every DWORD.
MOV is an expensive operation. Most ASM guru''s use X xor X to clear a register/memory position.
not sure how well this compiles in VC, but doing a large for loop and xor''ing every element with itself should be pretty fast.
actually, now that I think of it, im not sure how well this performs when accessing memory, because i''ve only used it on registers before, and C doesnt let you touch the registers.
heh... might actually turn out slower.
psuedo ASM:
mov ax, memory
xor ax
mov memory, ax
-or-
move memory,0
oh bah. ignore this entire post.
===============================================
If there is a witness to my little life,
To my tiny throes and struggles,
He sees a fool;
And it is not fine for gods to menace fools.
memset compiled to ASM is usually just a for loop MOVing 0 into every DWORD.
MOV is an expensive operation. Most ASM guru''s use X xor X to clear a register/memory position.
not sure how well this compiles in VC, but doing a large for loop and xor''ing every element with itself should be pretty fast.
actually, now that I think of it, im not sure how well this performs when accessing memory, because i''ve only used it on registers before, and C doesnt let you touch the registers.
heh... might actually turn out slower.
psuedo ASM:
mov ax, memory
xor ax
mov memory, ax
-or-
move memory,0
oh bah. ignore this entire post.

===============================================
If there is a witness to my little life,
To my tiny throes and struggles,
He sees a fool;
And it is not fine for gods to menace fools.
This is my signature. There are many like it, but this one is mine. My signature is my best friend. It is my life. I must master it as I must master my life. My signature, without me, is useless. Without my signature, I am useless.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement