dynamic Memory allocation and free in C -


lets have created string dynamically in program

char* s = malloc(sizeof(char) * 128); 

before start using s, how check whether memory allocated or not?

free(s); 

and before using free() , want check there other pointers pointing s .

malloc() returns pointer newly allocated memory or null.

so check null

char *s = malloc(128); /* sizeof (char), definition, 1 */ if (s == null) {     /* no memory allocated */ } else {     /* use memory */     free(s); } 

there other pointers pointing s points if (the programmer) created them.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -