[vlc-devel] [PATCH 1/1] block: use PAGE_SIZE to determine when to do malloc+memcpy
Ilkka Ollakka
ileoo at videolan.org
Sat Oct 4 10:44:57 CEST 2014
---
src/misc/block.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/misc/block.c b/src/misc/block.c
index 0a408cc..5b7ec6b 100644
--- a/src/misc/block.c
+++ b/src/misc/block.c
@@ -123,8 +123,6 @@ static void BlockMetaCopy( block_t *restrict out, const block_t *in )
/** Initial reserved header and footer size. */
#define BLOCK_PADDING 32
-/* Maximum size of reserved footer before shrinking with realloc(). */
-#define BLOCK_WASTE_SIZE 2048
block_t *block_Alloc (size_t size)
{
@@ -205,6 +203,13 @@ block_t *block_Realloc( block_t *p_block, ssize_t i_prebody, size_t i_body )
uint8_t *p_start = p_block->p_start;
uint8_t *p_end = p_start + p_block->i_size;
+ /* Maximum size of reserved footer before shrinking with realloc().
+ * FIXME: this is basicly limit where is
+ * meaningfull to do malloc/memcpy vs wasted memory size, so
+ * is PAGE_SIZE good limit or should it be n*PAGE_SIZE where n > 1?
+ */
+ const long block_waste_size = sysconf( _SC_PAGESIZE );
+
/* Second, reallocate the buffer if we lack space. This is done now to
* minimize the payload size for memory copy. */
assert( i_prebody >= 0 );
@@ -227,7 +232,7 @@ block_t *block_Realloc( block_t *p_block, ssize_t i_prebody, size_t i_body )
else
/* We have a very large reserved footer now? Release some of it.
* XXX it might not preserve the alignment of p_buffer */
- if( p_end - (p_block->p_buffer + i_body) > BLOCK_WASTE_SIZE )
+ if( p_end - (p_block->p_buffer + i_body) > block_waste_size )
{
block_t *p_rea = block_Alloc( requested );
if( p_rea )
--
1.8.4.5
More information about the vlc-devel
mailing list