Re: style question,itoa



Robert Latest schrieb:
Syren Baran wrote:
David Schwartz schrieb:

The caller has to 'free' 'retval' when it's done.
Its intended that way.
It might be more
sensible to have the caller pass in a buffer. This will allow the
caller to use a buffer on its stack if that makes the most sense for
it.
Dont intend to change that. I´m comfortable with that.
That's puzzling.
Not really. I dont like using arrays on the stack unless i can know for certain they cant overflow. But thats my personal style.
But you still need to add code that checks for malloc()s retun value.
Theoreticly, yes.
Since the program i´ll use it cant eat up memory at an alarming rate i prefer manual intervention (being able to tell the program not to accecpt further connections and deny further functions calls that can allocate memory).
Aside from that even a nun-NULL return value from malloc does not garantee that memory is available on Linux (see man 3 malloc).

robert
.



Relevant Pages

  • Re: Problem in printing string, created in another function.
    ... This makes me feel that since I assign retval memory using automatic ... the caller will need to free the memory after it's ... The caller MUST completely finish using the buffer you formatted the ... string into before the next time the formatting routine is called, ...
    (comp.lang.c)
  • Re: style question,itoa
    ... sensible to have the caller pass in a buffer. ... technically useless malloc and free calls, ... priori when memory allocations would fail. ...
    (comp.unix.programmer)
  • Re: Why "segmentation fault"?
    ... As you know if you do it like this then the caller has to release ... it because all you have to do as the caller is free the memory ... a static array of chars and return a pointer to that. ... pointer as well as the length of the buffer to the function - ...
    (comp.os.linux.development.system)
  • Re: memory related concerns
    ... i have a situation where i receive data in a buffer and i ... utiltimate aim is to return the header of the linked list to the caller ... run out of memory simultaneously. ...
    (comp.lang.c)
  • Re: Conversion from UTF32 to UTF8 for review
    ... time, which puts a performance burden on the caller, which should be counted in the total ... you would, upon completion, put a NUL character at the end of the buffer. ... app or an MFC app; and if it were being graded on performance, I'd give it a D- at best, ... The programmer protested that "I have to do malloc each time because I ...
    (microsoft.public.vc.mfc)