I have 5000+ strings pet-project for CLI and it can do some optional calculations and can output results to CLI or/and to file. Some new modules don't work.
Now I catch with GDB some strange segfaults and stack overflows, which I can't fix, though, I found all the places where the bugs are living. So, I see where and what's going wrong, but I have no idea how to fix it, because to fix it I have to spend a lot of time on learning some new tricky things in C - memory layouts and memory management.
I'm a novice to C and self-learning it as a hobby, so, to become familiar with memory management will take a long time, which I just don't have right now.
(I feel the need to learn some memory management golden rules, which can cover the whole program memory with nested calls, but I can't find points from which it's better to start)
Sorry, I can't fully describe in professional words what is going wrong in my program, but in general as I got it - it crushes because I don't know how to handle memory of structure copies properly, and how to manage memory safely in tricky(for me) hierarchy of function calls. I don't want to reduce amount of calls' levels cause of my intention to keep my code structure simple and readable.
I think that more experienced and well-educated in C people can fix my bugs just by editing my noobie designs in structure manipulations and memory management with advanced pointing technics, but.. I'm not that guy :(
So, my question is - What are the real cases, where it is impossible to fix the stack overflows and segmentation faults without changing the program design by separating its one exec to several smaller programs(execs) - control/interface module and functional modules?
In other words - What are the (memory management) cases, when you better to split your 1-process program to N-process program, than to redesign code structure to the loss of its readability?
I appreciate any practical or abstract examples, cause I try to figure out, if I'm in this kind of situation, or I'm not.
Now I have a choice - spend my time to understand really difficult to me part of CS - memory layouts and memory management, or spend my time on redesigning my code into multi-exec project.
I'm asking, cause I'm not sure, if the first direction will lead me to my actual goal.
I just want borders of using '1-exec-design' in C to be outlined a little.
Thanks for reading this.
You don't fix memory management issues by breaking your program up into multiple executables - you fix memory management issues by fixing your memory management code. I know that's not a satisfactory answer, but it is the answer.
C is not an easy language to learn, and I do not recommend it as a first language for anyone. It's an important language, yes, but it's not beginner-friendly at all. Even for people who are relatively experienced, it can be confusing and frustrating. Pointer syntax and behavior is not straightforward, memory management is very labor-intensive and easy to get wrong, and C gives you few tools to make it easy. Whole books have been written on how to manage data in C.
Without seeing your code it's impossible to give you any real guidance, but here are some suggestions:
If you have questions about a specific problem you're encountering, such as why you're getting a core dump when you execute some piece of code, then include that piece of code in your question, along with a description of what you expect to happen vs. what actually happens.
External links referenced by this document: