Slashdot Mirror


C Coding Tip - Self-Manage Memory Alllocation

An anonymous reader inputs: "The C programming language defines two standard memory management functions: malloc() and free(). C programmers frequently use those functions to allocate buffers at run time to pass data between functions. In many situations, however, you cannot predetermine the actual sizes required for the buffers, which may cause several fundamental problems for constructing complex C programs. This article advocates a self-managing, abstract data buffer. It outlines a pseudo-C implementation of the abstract buffer and details the advantages of adopting this mechanism."

6 of 142 comments (clear)

  1. Please by YellowElectricRat · · Score: 4, Funny

    This article, I believe, has already been published in the well known programmers' journal "No shit Sherlock - monthly"

  2. Memory Allocation by rmohr02 · · Score: 4, Funny

    Just like slashdot allocated extra space for the third "l" in "alllocation".

  3. Wow! by arkanes · · Score: 4, Funny
    Man, I never thought of that. An abstract memory buffer. What a concept! I don't need to define the lengths of everything at compile time then!

    Now, I'll need a nice short catchy name for it... oh! I know! I'll call it a heap!

  4. A memory leak IN THE SPECIFICATION?!? by MarkusQ · · Score: 4, Funny

    From the article:
    • The pLostBlock points to the linked list's last memory block.

    pLostBlock?!? This almost sounds as if it's designed to leak!

    -- MarkusQ

    P.S. Seriously, I think this is a fine idea, if not particularly earth shaking. But the typo was too ironic not to point out.

  5. Re:Um by E_elven · · Score: 2, Funny

    > Which means you don't have predictable destruction. Which means you don't have destructors.

    My GC does something like this:

    1) Allocate memory, reference count 1 ...
    N-1) When ref count reaches 0, we call destroy() on the object ...
    N) Free the memory

    --
    Marxist evolution is just N generations away!
  6. Re:What a crap story... by Anonymous Coward · · Score: 2, Funny

    How about this: Solve all of your memory management problems by switching to visual basic! All memory management is done automagically. No need to even think about it! Just hook up your data bound controls and write your logic code. No more memory worries :)