When.com Web Search

Search results

  1. Results From The WOW.Com Content Network
  2. C Memory Management - Stack Overflow

    stackoverflow.com/questions/24891

    In C the responsibility of ensuring your pointers point to memory you own is yours and yours alone. This requires an organized and disciplined approach, unless you forsake pointers, which makes it hard to write effective C. The posted answers to date concentrate on automatic (stack) and heap variable allocations.

  3. The sad truth is that C isn't really designed to encapsulate all those memory management issues. If you look at fairly high quality APIs like POSIX, you'll see that the common pattern is that you pass a pointer to a pointer to a function, which then allocates the memory, and that you later pass it again to a function that destroys it.

  4. Another Memory management aspect that is present in C++ but not in C, is that C++ have object oriented approach to classes . When an instance gets created the constructor of that instance is called, when that instance goes out of scope the destructor is called, this behavior is automated by the compiler, and is transparent to the programmer.

  5. Check how much stack memory your system needs and adjust the linker memory allocation accordingly (see the answers to this question). To reduce stack usage, avoid placing large data structures on the stack (for whatever value of "large" is relevant to you). edited May 23, 2017 at 12:09. Community Bot. 1 1.

  6. It will even tell you where potentially erroneous code could be in a non-invasive way. My own command line of choice is as follows. # Install valgrind. Remove this line of code if you already have it installed. apt install valgrind. # Now, compile and valgrind the C.

  7. 16. A big part of reliability comes from experience. Even if C++ is more reliable than C for resource management (RAII helps a lot there), an experienced C programmer may find it easier (and make less mistakes) implemeting it in C than in C++. Reliability comes from the programmer, not the language (the language can help or get in the way, but ...

  8. c - Implement own memory pool - Stack Overflow

    stackoverflow.com/questions/11749386

    Memory Management using Memory Pool - Memory Pool is the way to pre-allocate the blocks of memory of the same size. For example, various objects of the same class. Thus, it is more about designing the 'Memory Model' ofyour software. Example - An animated gif has various frames. Let's say each frame needs maximum 1024 KB only.

  9. 14. What you need to know about memory management in the simplest sense, is that you need to delete the memory that you allocate on the heap. So when creating an object like MyClass *myClass = new MyClass(x); you need to have some place in your code that frees/deletes this with a corresponding delete.

  10. struct Connection * new_node = new Connection (); new_node->_data = ... // whatever, set it up here. return new_node; } struct Connection * new_user = accept_connection (const char *name); users.append (new_user); So I have a new strategy for this next version of the project. So far what I am doing is creating objects with new () and assigning ...

  11. Memory management in C - Stack Overflow

    stackoverflow.com/questions/1870692

    7. You don't really 'create' instances of structures in C like that. Assuming that p points to a block of usable memory, you can just treat p as a pointer to your structure type: typedef struct {int x; long y;} a; a *p2 = (a*)p; int z = p2->x; // or, if you don't want p2: z = ((a*)p)->x; Once p is cast (implicitly or explicitly as above), you ...