Commit Graph

11 Commits

Author SHA1 Message Date
Avi Kivity
fa5c61d4e4 temporary_buffer: fix wrong oom check
If malloc(0) is allowed to return nullptr, so don't throw an exception in
that case.
2014-12-10 10:33:29 +02:00
Avi Kivity
441331f158 temporary_buffer: fix missing exception
Since we switched temporary_buffer to malloc(), it now longer throws
an exception after running out of memory, which leads to a segfault
when referencing a null buffer.
2014-12-10 09:53:37 +02:00
Tomasz Grabiec
f556172619 temporary_buffer: make empty buffer don't need to malloc() 2014-12-03 13:15:09 +01:00
Tomasz Grabiec
1c49669f59 temporary_buffer: introduce operator bool()
It's used as a test for emptiness by convention.

Allows for things like:

  if (buf) {
     // not empty
  }
2014-12-03 13:15:09 +01:00
Avi Kivity
fe8ed68878 temporary_buffer: use raw object deleter to destroy allocated buffer
Removes an allocation.
2014-10-21 11:23:41 +03:00
Avi Kivity
5a6771ee33 Drop eclipse workaround for reference qualified member functions
Latest eclipse understands it.
2014-10-19 17:42:47 +03:00
Avi Kivity
a1f3708fab packet: optimize sharing
Move reference counting into the deleter core, instead of relegating it
to a shared_deleter (which has to be allocated) and an external reference
counted (also allocated).  This dramatically reduces dynamic allocations.
2014-09-23 18:57:11 +03:00
Avi Kivity
9994e09792 temporary_buffer: stop using internal_deleter
Not much point now since packet doesn't use it.
2014-09-23 18:08:46 +03:00
Avi Kivity
e223f748ec core: great deleter rename
deleter::share() is causing massive amounts of allocation.  First,
since usually a packet's deleter is not a shared_deleter, we need to
allocate that shared_deleter.  Second, we need an external reference
count which requires yet another allocation.

Making reference counting part of the deleter class would solve both of
these problems, but we cannot easily do that, since users hold
std::unique_ptr<deleter> which is clearly not sharable.

We could do a massive s/unique_ptr/shared_ptr/ here, but that would have
the side effect of making sharing "too easy" - you simply copy the pointer.
We'd like to keep it explicit.

So to make the change easier, rename the existing unique_ptr<deleter> as
plain "deleter", whereas the old "deleter" becomes deleter::impl:

  old name              new name
  --------              --------
  deleter               deleter::impl
  unique_ptr<deleter>   deleter

with exactly the same semantics.  A later patch can then add explicit sharing.
2014-09-23 11:15:31 +03:00
Avi Kivity
bddbb3d938 temporary_buffer: add release() method
This allows the caller to take responsibility for deleting the data.

Useful when different data structures use the deleter infrastructure.
2014-09-23 10:37:56 +03:00
Avi Kivity
f81760aba7 spit out temporary_buffer into its own file 2014-09-17 12:42:30 +03:00