Re: declaring a function as static..
- From: Giorgos Keramidas <keramida@xxxxxxxxxxxxxxx>
- Date: Fri, 28 Sep 2007 03:45:02 +0300
On Thu, 27 Sep 2007 23:43:17 -0000, nass <athanasios.si...@xxxxxxxxx> wrote:
On Sep 28, 1:31 am, Giorgos Keramidas <keram...@xxxxxxxxxxxxxxx> wrote:
On Thu, 27 Sep 2007 22:09:58 -0000, nass <athanasios.si...@xxxxxxxxx> wrote:
hello everyone,
i am using a hacked version of the utilities df and du to get the disk
free space and folder size respectively..
when i say hacked i mean i just got the df.c and du.c from core-utils
renamed their main() function to dfmain() and dumain(), commented out
all the printf statements (since i only wanted the numbers ) and i
compiled them along with my code....
problem is df and du as designed for one-off operation, that is the
program runs once, ends and its resources are freed by the OS (cause
it has alot of static declarations as i see in the sources)
on the contrary my program is running in a loop (its a processing
algorithm) so it appears that running the dfmain() or the dumain()
function from my code again and again consumes resources that do not
get freed..
is there a way to sort of declare the whole df.c and du.c as static?
Sort of forking a copy and reading the results through a pipe (which can
be _very_ inefficient, depending on the frequency of the forks you plan
to do), no...
We had to do something similar with prstat(1) and vmstat(1) at work, and
we ended up modifying prstat_main() and vmstat_main() to use two sorts
of buffers:
* Long-lived reusable buffers (declared static)
* Short-lived buffers grabbed with malloc() and released with
free() *every* time the respective xxx_main() function runs.
You'll have to do something similar.
hmmm im not sure what was the purpose of each of the 2 buffer
categories...
The first category was introduced by me after we finished the first part
of the work, and we found that it was all working.
unless you mean that you actually sort of re-declared all the vmstat
variables...
The way the Solaris vmstat(1) utility works depends on keeping around a
pair of "kstat snapshots". We could always rely on libumem.so.1 or some
other malloc() implementation that caches freed objects to give us back
precisely the kstat snapshot we released just a second or so ago.
We could also malloc() two kstat snapshots, and reuse them every time we
iterated through vmstat_main(). The snapshots are only used to collect
/some/ kernel information and then thrown away, so we added:
int vmstat_init(void);
int vmstat_fini();
to take care of preallocating any buffers we would keep around while the
program was running, and free them just once before the program exited.
For *very* short-lived objects, we didn't bother to preallocate
anything. It wasn't really worth the development time, and it was
better to spend this time looking for places where memory would be
"leaked" if we simply copied vmstat(1) in its original form.
- Giorgos
.
- References:
- declaring a function as static..
- From: nass
- Re: declaring a function as static..
- From: Giorgos Keramidas
- Re: declaring a function as static..
- From: nass
- declaring a function as static..
- Prev by Date: Re: declaring a function as static..
- Next by Date: Sending Data Via a Socket
- Previous by thread: Re: declaring a function as static..
- Next by thread: Re: declaring a function as static..
- Index(es):
Relevant Pages
|