The value of obstack rests upon:
1. It reduces frequency of invoking malloc() and free() system API.
2. You can arbitrarily change the size of object just added to the stack.
How does obstack work?
Namely, obstack is objects in stack, but don't conjecture it with stack very much. Practically, after a new object being added to the stack, the previous objects added in the stack can never be moved or changed.
So you should comprehend the organization of obstack as simple as possible. If you want new memory, that is, for the room of a new object, first resort to the existed pre-allocated block, if rest room in the block caters for the need, just use it, or else malloc a new big block for the need.
见原出处
1. It reduces frequency of invoking malloc() and free() system API.
2. You can arbitrarily change the size of object just added to the stack.
How does obstack work?
Namely, obstack is objects in stack, but don't conjecture it with stack very much. Practically, after a new object being added to the stack, the previous objects added in the stack can never be moved or changed.
So you should comprehend the organization of obstack as simple as possible. If you want new memory, that is, for the room of a new object, first resort to the existed pre-allocated block, if rest room in the block caters for the need, just use it, or else malloc a new big block for the need.