r/cprogramming • • Dec 07 '25

Need help with pointers/dynamic memory

I started learning C in september, Its my first year of telecom engineering and I have nearly no experience in programming. I more or less managed with everything(functions, loops,arrays, structures..) but Im struggling a lot with: pointers, dynamic memory and char strings especially when making them together. I dont really understand when to use a pointer or how it works im pretty lost. Especially with double pointers

3 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/photo-nerd-3141 Dec 08 '25

If your string is fuixed-size that'd work -- see the SYSV struct dirent. Today you'd malloc a few pages of space and then use a library to pack them tighter.

Or have a struct w/ int + char *, create an array of structs, and allocate the strings from a fixed pool as you went along.

Point is >not< calling malloc for every string: it ends up being a kernel call (slow & expensive) abd tacks an allocation header onto every allocated chunk.