当你分配对象的子对象时,如果子对象的生存时间和父对象基本相同,他们应该被同时分配以使他们在GC堆中的位置也是相近的。
When you allocate the children of an object, if the children need to have similar life time as their parent they should be allocated at the same time so they will stay together on the GC heap.
对大多数收集器实现而言,分配子系统持有一个自由堆内存池,应用程序通过分配对象使用该池,然后由收集器通过清理来补充该池。
For most collector implementations, the allocation subsystem keeps a pool of free heap memory, consumed by the application through allocating objects and replenished by the collector through sweeping.
C+ +向程序员提供了在堆或堆栈中分配对象的选择。
C + + offers programmers a choice of allocating objects on the heap or on the stack.
应用推荐