Discussion:
Memory problem
(too old to reply)
zhe
2005-02-17 08:18:48 UTC
Permalink
I tried to allocate memory with Malloc and return the result to
(*pUserContext)->memory like below:

(*pUserContext)->memory = Malloc(userProcessSize);

memset(((*pUserContext)->memory), '\0', userProcessSize);

However, when I test the size of Context, it says UserContext is pointing to
NULL, or = 0,

please help!

Thanks

Zhe
Timothy Finley
2005-02-18 05:59:20 UTC
Permalink
Is pUserContext a double pointer? You are using the address of operator
and the -> operator. Both of these dereference the pointer. Do you just
want to only do the -> ?

Tim
cs412050
2005-02-19 07:43:31 UTC
Permalink
It seems like you didn't allocate memory for *pUserContext.
When you see a double pointer, you may think that it is a sort of table.
And each entry of the table is pointing to Actual memory block, UserContext.
Although entry is a pointer to an object, you still need memory to
store entries.

Your memset just nullifies an entry.
If you already allocated table, then consider some place else.
NULL pointer can be caused by something unintuitive thing you made.
Hope this helps.

Raymond.
Zhe
2005-02-19 19:15:25 UTC
Permalink
Thanks, you are right, I only allocated memory for userContext->memory, but
forgot to allocate space for the actual userContext structure

thx

Zhe

Loading...