Re: Memory pool interface design

2015-05-16 Thread Elazar Leibovich
The question of whether to use a global malloc function, or to use a function pointer is orthogonal to my question. My question is, should I support the case of malloc failure. On one hand, it complicates the API significantly, but on the other hand it might be useful for some use cases. It's

Re: Memory pool interface design

2015-05-16 Thread Orna Agmon Ben-Yehuda
Hi Elazar, I find that malloc failure checking is vital (within the user program) even on a regular system with gigabytes of memory. For example, when the program gets into a recursive loop which allocates memory and then digs deeper. In other cases, It is useful to check the return value of

Re: Memory pool interface design

2015-05-16 Thread Elazar Leibovich
Thanks Orna, My understanding is, that in stock Linux kernel, a process that allocates too much memory is unlikely to receive NULL from malloc. The more likely scenario is, the whole system would swap out pages, and the OOM killer would, hopefully, kill the offending process. During that time it

Re: Memory pool interface design

2015-05-16 Thread Oleg Goldshmidt
Elazar Leibovich elaz...@gmail.com writes: My question is, should I support the case of malloc failure. On one hand, it complicates the API significantly, but on the other hand it might be useful for some use cases. This sounds like, can you guys tell me what my requirements are? ;-) If I

Re: Memory pool interface design

2015-05-16 Thread Elazar Leibovich
I think that I didn't explain myself correctly. Let me try again. I'm writing a C library, and I want it to be useful not only in Linux userland, but also in other contexts, such as embedded devices, and inside the Linux kernel. This library sometimes allocates memory. If I'll just allocate

Re: Memory pool interface design

2015-05-16 Thread guy keren
as a rule - if it's a general-purpose library,k and it can fail - it must return an error using the language's natural error mechanism. in C - this comes as a return status. i *have* seen malloc returning NULL in some situations. the application that uses your library may decide to simply