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.
本文介绍了Obstack内存管理机制的工作原理及其优势。Obstack能够减少调用系统API malloc() 和 free() 的频率,并允许灵活调整堆栈中对象的大小。通过预先分配内存块并在需要时扩展,Obstack有效地管理内存使用。


被折叠的 条评论
为什么被折叠?



