httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@ai.mit.edu (Robert S. Thau)
Subject Re: set_flag and memory
Date Thu, 06 Jun 1996 15:05:12 GMT
q: Would it be an idea to have a global errstr or something
   which you can sprintf to, a lot of modules seem to claim
   one with just errstr[MAX_LEN_STRING] which is a seems a
   waste of space.

Yeeach!!!! If those are local variables to the functions in question,
they aren't wasting space except on the stack (that's the case everyplace
I'm aware of, and I *hope* it's the case everywhere else).  However,
putting it in a global would kill safety for preemptive threading.  (With
nonpreemptive threads, you have the option of copying the result from
the global 'errstr' elsewhere before yielding control, but this sort of
thing is still very bad form).

q: Memory alloc policy, what is better: (Case: I expect an
   arbitary long string, break it up in bite size chunks and
   compare these with some other bite size chunks. The original
   string can be very long, several kilobytes and the bite size
   chunks should be short, say less than a 100 bytes but might
   occasionally long. 

        1. use a char buff[VERY_LONG] and tmp1[NORMAL], tmp2[NORMAL]
           and flash errors when anything is too long

        2. use a palloc/pstrdup for the buff, but still use 
           tmp1[NORMAL], tmp2[NORMAL].

        3. use palloc for all three.

        4. use palloc for all three and even bother freeing the tmp1 and
           tmp2 as they are in a loop.

See the groups_for_user routine in mod_auth.c for one way of dealing
with this sort of situation.

rst

Mime
View raw message