Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
86997e00
Commit
86997e00
authored
Sep 27, 2009
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
block_Alloc: use posix_memalign()
parent
2c66458d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
15 deletions
+30
-15
src/misc/block.c
src/misc/block.c
+30
-15
No files found.
src/misc/block.c
View file @
86997e00
...
...
@@ -89,10 +89,10 @@ static void BlockMetaCopy( block_t *restrict out, const block_t *in )
out
->
i_nb_samples
=
in
->
i_nb_samples
;
}
/* Memory alignment */
/* Memory alignment
(must be a multiple of sizeof(void*) and a power of two)
*/
#define BLOCK_ALIGN 16
/* Initial
size of reserved header and footer
*/
#define BLOCK_PADDING
_SIZE
32
/* Initial
reserved header and footer size (must be multiple of alignment)
*/
#define BLOCK_PADDING
32
/* Maximum size of reserved footer before we release with realloc() */
#define BLOCK_WASTE_SIZE 2048
...
...
@@ -100,24 +100,39 @@ block_t *block_Alloc( size_t i_size )
{
/* We do only one malloc
* TODO: bench if doing 2 malloc but keeping a pool of buffer is better
* TODO: use memalign
* 16 -> align on 16
* 2 * BLOCK_PADDING_SIZE -> pre + post padding
* 2 * BLOCK_PADDING -> pre + post padding
*/
const
size_t
i_alloc
=
i_size
+
2
*
BLOCK_PADDING_SIZE
+
BLOCK_ALIGN
;
block_sys_t
*
p_sys
=
malloc
(
sizeof
(
*
p_sys
)
+
i_alloc
)
;
block_sys_t
*
p_sys
;
uint8_t
*
buf
;
#define ALIGN(x) (((x) + BLOCK_ALIGN - 1) & ~(BLOCK_ALIGN - 1))
#ifdef HAVE_POSIX_MEMALIGN
const
size_t
i_alloc
=
ALIGN
(
sizeof
(
*
p_sys
))
+
(
2
*
BLOCK_PADDING
)
+
ALIGN
(
i_size
);
void
*
ptr
;
if
(
posix_memalign
(
&
ptr
,
BLOCK_ALIGN
,
i_alloc
)
)
return
NULL
;
p_sys
=
ptr
;
buf
=
p_sys
->
p_allocated_buffer
+
(
-
sizeof
(
*
p_sys
)
&
(
BLOCK_ALIGN
-
1
));
#else
const
size_t
i_alloc
=
sizeof
(
*
p_sys
)
+
BLOCK_ALIGN
+
(
2
*
BLOCK_PADDING
)
+
ALIGN
(
i_size
);
p_sys
=
malloc
(
i_alloc
);
if
(
p_sys
==
NULL
)
return
NULL
;
/* Fill opaque data */
p_sys
->
i_allocated_buffer
=
i_alloc
;
buf
=
(
void
*
)
ALIGN
((
uintptr_t
)
p_sys
->
p_allocated_buffer
);
#endif
buf
+=
BLOCK_PADDING
;
block_Init
(
&
p_sys
->
self
,
p_sys
->
p_allocated_buffer
+
BLOCK_PADDING_SIZE
+
BLOCK_ALIGN
-
((
uintptr_t
)
p_sys
->
p_allocated_buffer
%
BLOCK_ALIGN
),
i_size
);
block_Init
(
&
p_sys
->
self
,
buf
,
i_size
);
p_sys
->
self
.
pf_release
=
BlockRelease
;
/* Fill opaque data */
p_sys
->
i_allocated_buffer
=
i_alloc
-
sizeof
(
*
p_sys
);
return
&
p_sys
->
self
;
}
...
...
@@ -216,7 +231,7 @@ block_t *block_Realloc( block_t *p_block, ssize_t i_prebody, size_t i_body )
if
(
p_end
-
(
p_block
->
p_buffer
+
i_body
)
>
BLOCK_WASTE_SIZE
)
{
const
ptrdiff_t
i_prebody
=
p_block
->
p_buffer
-
p_start
;
const
size_t
i_new
=
requested
+
1
*
BLOCK_PADDING
_SIZE
;
const
size_t
i_new
=
requested
+
1
*
BLOCK_PADDING
;
block_sys_t
*
p_new
=
realloc
(
p_sys
,
sizeof
(
*
p_sys
)
+
i_new
);
if
(
p_new
!=
NULL
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment