This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Fastest way to clear a block of memory


Fastest way to clear a block of memory

Postby fzammetti » Jul 25, 2002 @ 9:54pm

Hey guys... general question here... if I allocate a block of memory with...

unsigned short int* memBlock = (unsigned short int*)malloc(mbSize);

What would be the FASTEST way to clear said block of memory? Not deallocate it, but write all 0's to it (or some arbitrary value, but 0 is what I'm thinking).

I'm assuming that...

for (int i = 0; i < mbSize; i++) {
*(memBlock + i) = 0;
}

..would NOT be the fastest way, right?

Thanks all!
...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby BurningSheep » Jul 25, 2002 @ 10:03pm

I think memset is the fastest way to clear the memory

memset(memblock, 0, mbSize);
Do you want custom Snails levels? Click
User avatar
BurningSheep
pm Insider
 
Posts: 1226
Joined: Apr 12, 2002 @ 11:49pm
Location: The Netherlands


Postby refractor » Jul 26, 2002 @ 9:03am

If you mean you'd like the memory cleared for you when it's given to you, simply use calloc instead of malloc.

If you want to clean it yourself, then BurningSheep's suggestion is the one I'd go for.

... unless it's a severe problem and you have lots of time and patience and you want to start playing with DMA (which would actually be a slower way of clearing the memory, but could run contiguously with other processing).

Cheers,

Refractor
User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby fzammetti » Jul 26, 2002 @ 3:32pm

...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


clearing a block of memory

Postby Conan » Jul 30, 2002 @ 12:22pm

What is Best in Life ?
User avatar
Conan
pm Member
 
Posts: 1309
Joined: Dec 24, 2001 @ 5:16am
Location: the Shades, Ankh-Morpock


Postby refractor » Jul 30, 2002 @ 12:54pm

User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby Dan East » Jul 30, 2002 @ 3:24pm

User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Postby Conan » Jul 30, 2002 @ 4:37pm

What is Best in Life ?
User avatar
Conan
pm Member
 
Posts: 1309
Joined: Dec 24, 2001 @ 5:16am
Location: the Shades, Ankh-Morpock


Postby britcode » Aug 2, 2002 @ 4:26am

britcode
 


Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum