[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: question on select & FD_ISSET



> -----Original Message-----
> From: seb@highlab.com
> Sent: Thu, 15 Mar 2007 11:15:54 -0600
> To: ejr@inbox.com
> Subject: Re: question on select & FD_ISSET
> 
> Junior <ejr@inbox.com> wrote:
>> True, but it seems to me that if I FD_SET them at the top of the loop
>> without FD_CLR first, I will be expanding the set unnecessarily which
>> would waste memory (eventually run out).
>> Since FD_SET adds the set and FD_CLR clears it from the list, FD_SET
>> without FD_CLR would duplicate fds in the set. Not so?
> 
> It's good that you look out for memory leaks, but in this case there's
> nothing to worry about.
> 
> fd_set is a fixed-size array of bits, indexed by the file descriptor
> number.  FD_SET and FD_CLR just modify the fd's bit in that array.
> 
> It's so simple that it can't leak memory.  After you've created an
> fd_set,
> its size never changes.
> 
> You can see its defition in /usr/include/sys/select.h.
> 

Thanks much for claering this up.
Most appreciated.
--Jr.

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Check it out at http://www.inbox.com/earth



Reply to: