I need some useful functions that faster than the original. (Original - C++'s functions)
For Example:
#include <time.h>
#include <stdio.h>
#include <Windows.h>
struct TestMemory {
double a,b,c;
};
void* __TestMemory__Sample=0;
int WINAPI WinMain(HINSTANCE h1,HINSTANCE h2,LPSTR str,int i) {
AllocConsole();
__TestMemory__Sample=calloc(1,sizeof(TestMemory));
TestMemory* test=(TestMemory*)malloc(sizeof(TestMemory));
clock_t c1=clock(),c2;
for (int i=0;i<100000000;i++)
memcpy(test,__TestMemory__Sample,sizeof(TestMemory));
c1=clock()-c1;
c2=clock();
for (int i=0;i<100000000;i++)
memset(test,0,sizeof(TestMemory));
c2=clock()-c2;
printf("memcpy: %d\nmemset: %d\nradio: %f (set/cpy)",c1,c2,c2/(float)c1);
getchar();
}
Output:
memcpy: 1410
memset: 3250
radio: 2.304965 (set/cpy)
This function replace the current way to zero memory.
What it does:
Create global pointer ,first set in it zeroed memory.
After that ,when you want to allocate zeroed memory.
Allocate memory with malloc
and then copy the zeroed memory (Global variable)
to this memory.
Note: If I cant ask this thing here then delete it. (Someone navigated me here)
memcpy: 141861 memset: 139421 radio: 0.982800
– Loki Astari Jul 31 '12 at 22:28