Jerry (14)
Usenet Archive
- Joined
- Jul 7, 2006
- Messages
- 4
- Reaction score
- 0
Consider the following codes:
static int POOL_SIZE 256
static int BUFF_SIZE 1024
static int *buff_pool[POOL_SIZE]={NULL};
void init_buff(int idx)
{
int i;
buff_pool[idx]=(int*)malloc(BUFF_SIZE * sizeof(int));
for (i=0; i<BUFF_SIZE;i+=)
buff_pool[idx] = 1;
}
There is an alternative way is to use memset instead of for loop, but it is said that there is no guarantee that the machine representation of zero is all-bits-zero. My codes need to work with different compiler and machine.
I wonder if there is a better and fast way to initialize the dynamic array without running the whole for loop?
Thanks
Jerry
static int POOL_SIZE 256
static int BUFF_SIZE 1024
static int *buff_pool[POOL_SIZE]={NULL};
void init_buff(int idx)
{
int i;
buff_pool[idx]=(int*)malloc(BUFF_SIZE * sizeof(int));
for (i=0; i<BUFF_SIZE;i+=)
buff_pool[idx] = 1;
}
There is an alternative way is to use memset instead of for loop, but it is said that there is no guarantee that the machine representation of zero is all-bits-zero. My codes need to work with different compiler and machine.
I wonder if there is a better and fast way to initialize the dynamic array without running the whole for loop?
Thanks
Jerry