Go to the FreeLists Home Page Home Signup Help Login
 



[openbeosstorage] || [Date Prev] [05-2002 Date Index] [Date Next] || [Thread Prev] [05-2002 Thread Index] [Thread Next]

[openbeosstorage] Memory allocation

  • From: Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>
  • To: openbeosstorage@xxxxxxxxxxxxx
  • Date: Fri, 17 May 2002 18:57:09 +0200 (MET DST)
Hi folks,

I just want to report that I went through all the classes (the library
classes only -- the tests aren't that critical) and fixed the `new' memory
allocations.

Though it is common practice (for a good reason) to check the return value 
of a malloc() call, somehow using `new' does make people (including
myself) lazy. Of course `new' can fail and it usually throws a bad_alloc
exception, when it does. Usually means, that disabling exceptions via
compiler flag makes it return NULL instead. With exceptions enabled, one
can use `new(nothrow)' which always behaves that way (<new> has to be
included for this one).

So what I did is the following: I replaced most of the `new' invocations
by `new(nothrow)' followed by a check for the return value. For a few
occurences I rather caught the exception. Some other code had to be
adjusted accordingly, e.g. helper functions that returned void now return
a status_t.

Things should be safer now.

CU, Ingo






[ Home | Signup | Help | Login | Archives | Lists ]

All trademarks and copyrights within the FreeLists archives are owned by their respective owners.
Everything else ©2007 Avenir Technologies, LLC.