c++ - deleting 2D Linked List array, How to? -


i have function delete 2 dimensional struct, not fast, guess there faster way this(like memset or something), idea appreciated;)

 void freealllistnode(listnodeptr *sptr[][10]) {   listnodeptr temp; (char = 0; i<19; i++){     (char di = 0; di<10; di++){         while (sptr[i][di] != null){             temp = *(sptr[i] + di);             *(sptr[i] + di) = temp->next;             free(temp);         }     }   } } 

and struct definition, in case if it's necessary

typedef struct listnode{ char* val ; struct listnode *next; }listnode; using listnodeptr = listnode*; 

no. memset never replacement malloc/free, in circumstance. different things. proposal memset somehow replacement malloc/free fundamental misunderstanding of how dynamic memory, , dynamic scope allocation works.

the thing remotely implement standard c++ library containers custom allocation class. is, std::list, std::vector, , others, , none of manual link list implementation.

standard c++ library containers take optional template parameter specify custom allocator class. custom allocator class have written manages dynamic memory allocation container, along lines of allocating large chunks of memory, , doling them out, piecewise, each value placed container. then, when container gets destroyed, allocated memory disposed of in few, short, deletes.

it would, of course, possible implement approach manual link list implementation. it's lot of work anyway, , long work has done, why waste more time manual link list, use std::list.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -