[vlc-commits] block: include left and right padding when memory mapping
Rémi Denis-Courmont
git at videolan.org
Mon Aug 31 18:32:06 CEST 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug 31 19:30:59 2015 +0300| [5dc2d7fce85f944c3c5c05568fc769f3d0cb1c3c] | committer: Rémi Denis-Courmont
block: include left and right padding when memory mapping
This avoids reallocating and copying the block in block_Realloc() in
some cases.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5dc2d7fce85f944c3c5c05568fc769f3d0cb1c3c
---
src/misc/block.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/misc/block.c b/src/misc/block.c
index c821320..c5d9f62 100644
--- a/src/misc/block.c
+++ b/src/misc/block.c
@@ -319,6 +319,10 @@ block_t *block_mmap_Alloc (void *addr, size_t length)
if (addr == MAP_FAILED)
return NULL;
+ long page_mask = sysconf(_SC_PAGESIZE) - 1;
+ size_t left = ((uintptr_t)addr) & page_mask;
+ size_t right = (-length) & page_mask;
+
block_t *block = malloc (sizeof (*block));
if (block == NULL)
{
@@ -326,7 +330,9 @@ block_t *block_mmap_Alloc (void *addr, size_t length)
return NULL;
}
- block_Init (block, addr, length);
+ block_Init (block, ((char *)addr) - left, left + length + right);
+ block->p_buffer = addr;
+ block->i_buffer = length;
block->pf_release = block_mmap_Release;
return block;
}
More information about the vlc-commits
mailing list