luanote / manualgc Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/manualgc
Automatically exported from code.google.com/p/manualgc
A manual garbage collector for C Copyright (c) 2008 , Cloud Wu . All rights reserved. http://code.google.com/p/manualgc/ http://www.codingnow.com ANY USE IS AT YOUR OWN RISK At first, you should call "gc_init" to initialize the environment. You may not call "gc_exit" at the end, becuase the OS will release all the resouce used by your process. void gc_init(); void gc_exit(); Then, you can use 'gc_malloc' to allocate a memory block . It's return value is the pointer to the memory (like malloc). void* gc_malloc(size_t sz,void *parent,void (*finalizer)(void *)); void* gc_realloc(void *p,size_t sz,void *parent); *sz* is the the size requested *parent* should be the memory's life time depend on. *parent* can be 0 , that is to say the memory is temporary. *finalizer* will be called when the memory collect. *finalizer* can be 0 , collector will do nothing. "gc_enter" and "gc_leave" is important , they tell the collector the life time of temporary memory blocks. All the memory allocated by "gc_new" after a "gc_enter" can be collect after "gc_leave", only if you link them to the others be related to the root , or tell "gc_leave" what you want to extend the life time. void gc_enter(); void gc_leave(void *p,...); You don't need put enter/leave in every function. If your program have a main loop, put one "gc_enter" before entering the main loop, and put one "gc_leave" is enough. For example: while (!quit) { gc_enter(); quit=mainloop(); gc_leave(0); } You can use "gc_link" to establish or remove the relationship of two memory block. (ps. Pass parent into gc_malloc or gc_realloc will establish the relationship automatic) void gc_link(void *parent,void *prev,void *now); Unlink "prev" from "parent" first, and then link "now" to the "parent". For example, If you do a->b = c; // a and c are both gc memory block Then you should call gc_link(a,a->b,c); You can also link a memory block to the root by pass "parent" 0. This is useful when you want to hold a global variable. Collector will not be executed automatically. void gc_collect(); This will collect all the memory block that can no longer be otherwise accessed. Before free it , collector will call the finalizer if you provided. void gc_dryrun(); Only for debug, it will print some useful information instead of collecting the garbage.
在cache_flush函数中,有
while (...) {
// ...
if (parent==-1) {
return;
}
// ...
}
E.cache_dirty=false;
cache_dirty应该是当前是否存在cache或cache是否flush
out的标记位吧。
那这里的return应该是break吧?
在cache
nodes未完全时,while循环就会遇到parent=-1,如果这里直接
return,E.cache_dirty=true不会执行,虽然当前的cache
nodes已全部被flush out了。
Original issue reported on code.google.com by [email protected]
on 4 May 2009 at 8:51
看到源代码中有如下三个宏:
#define my_malloc malloc
#define my_free free
#define my_realloc realloc
我想是可以用来自定义内存分配器的吧,那么是否可以把这��
�分通过接口或者宏定义开放出来,
而不需要修改.c文件中的这三个宏了。
Original issue reported on code.google.com by [email protected]
on 30 Oct 2008 at 9:34
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.