Possible Duplicate:
What is malloc doing in this code?
Can aynone explain what this code do, especially “malloc”? I use this in C with MPI…
vector = ( double * ) malloc ( size_of_vector * sizeof ( double ) );
for ( i = 0; i < size_of_vector; i++ ) {
vector[i] = (double) ( i + 0.211 );
}
I know this for malloc:
The function malloc() returns a pointer to a chunk of memory of size
size, or NULL if there is an error. The memory pointed to will be on
the heap, not the stack, so make sure to free it when you are done
with it.
It allocates enough memory to store
size_of_vectordoubles and then initializes that memory to holdsize_of_vectordoubles each with a value calculated based on its position in the vector.The
malloccall allocates the memory.