Add support for sized deallocation.
This adds a new `sdallocx` function to the external API, allowing the size to be passed by the caller. It avoids some extra reads in the thread cache fast path. In the case where stats are enabled, this avoids the work of calculating the size from the pointer. An assertion validates the size that's passed in, so enabling debugging will allow users of the API to debug cases where an incorrect size is passed in. The performance win for a contrived microbenchmark doing an allocation and immediately freeing it is ~10%. It may have a different impact on a real workload. Closes #28
This commit is contained in:
committed by
Jason Evans
parent
c3f8650749
commit
4cfe55166e
@@ -38,6 +38,7 @@
|
||||
<refname>xallocx</refname>
|
||||
<refname>sallocx</refname>
|
||||
<refname>dallocx</refname>
|
||||
<refname>sdallocx</refname>
|
||||
<refname>nallocx</refname>
|
||||
<refname>mallctl</refname>
|
||||
<refname>mallctlnametomib</refname>
|
||||
@@ -120,6 +121,12 @@
|
||||
<paramdef>void *<parameter>ptr</parameter></paramdef>
|
||||
<paramdef>int <parameter>flags</parameter></paramdef>
|
||||
</funcprototype>
|
||||
<funcprototype>
|
||||
<funcdef>void <function>sdallocx</function></funcdef>
|
||||
<paramdef>void *<parameter>ptr</parameter></paramdef>
|
||||
<paramdef>size_t <parameter>size</parameter></paramdef>
|
||||
<paramdef>int <parameter>flags</parameter></paramdef>
|
||||
</funcprototype>
|
||||
<funcprototype>
|
||||
<funcdef>size_t <function>nallocx</function></funcdef>
|
||||
<paramdef>size_t <parameter>size</parameter></paramdef>
|
||||
@@ -228,7 +235,8 @@
|
||||
<function>rallocx<parameter/></function>,
|
||||
<function>xallocx<parameter/></function>,
|
||||
<function>sallocx<parameter/></function>,
|
||||
<function>dallocx<parameter/></function>, and
|
||||
<function>dallocx<parameter/></function>,
|
||||
<function>sdallocx<parameter/></function>, and
|
||||
<function>nallocx<parameter/></function> functions all have a
|
||||
<parameter>flags</parameter> argument that can be used to specify
|
||||
options. The functions only check the options that are contextually
|
||||
@@ -312,6 +320,15 @@
|
||||
memory referenced by <parameter>ptr</parameter> to be made available for
|
||||
future allocations.</para>
|
||||
|
||||
<para>The <function>sdallocx<parameter/></function> function is an
|
||||
extension of <function>dallocx<parameter/></function> with a
|
||||
<parameter>size</parameter> parameter to allow the caller to pass in the
|
||||
allocation size as an optimization. The minimum valid input size is the
|
||||
original requested size of the allocation, and the maximum valid input
|
||||
size is the corresponding value returned by
|
||||
<function>nallocx<parameter/></function> or
|
||||
<function>sallocx<parameter/></function>.</para>
|
||||
|
||||
<para>The <function>nallocx<parameter/></function> function allocates no
|
||||
memory, but it performs the same size computation as the
|
||||
<function>mallocx<parameter/></function> function, and returns the real
|
||||
|
Reference in New Issue
Block a user