Taming the malloc/free beast — tips & tricks
I’ve been using C on some projects for a master’s degree but have never built production software with it. (.NET & Javascript are my bread and butter.) Obviously, the need to free()
memory that you malloc()
is critical in C. This is fine, well and good if you can do both in one routine. But as programs grow, and structs deepen, keeping track of what’s been malloc
‘d where and what’s appropriate to free gets harder and harder.
When should I use free() in C?
The code works as it is supposed to, though it never frees the memory allocated by malloc()
.
C – Design your own free( ) function
Today, I appeared for an interview and the interviewer asked me this,
Invalid Pointer Error when Freeing 3 pointer Grid Cells in Snake Game Project
I’m working on a Snake game project for my school where I need to create a grid using triple pointers (a matrix for the grid with each cell containing an 8-character string) along with the snake representation.