Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-1.1
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-1.1
Commits
daa7c08f
Commit
daa7c08f
authored
Mar 24, 2008
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Realloc block if a large extent of the footer becomes unused
Should fix #1536
parent
0649ebcd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
3 deletions
+29
-3
src/misc/block.c
src/misc/block.c
+29
-3
No files found.
src/misc/block.c
View file @
daa7c08f
...
...
@@ -69,16 +69,22 @@ static void BlockRelease( block_t *p_block )
free
(
p_block
);
}
/* Memory alignment */
#define BLOCK_ALIGN 16
/* Initial size of reserved header and footer */
#define BLOCK_PADDING_SIZE 32
/* Maximum size of reserved footer before we release with realloc() */
#define BLOCK_WASTE_SIZE 2048
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: 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
*/
const
size_t
i_alloc
=
i_size
+
2
*
BLOCK_PADDING_SIZE
+
16
;
const
size_t
i_alloc
=
i_size
+
2
*
BLOCK_PADDING_SIZE
+
BLOCK_ALIGN
;
block_sys_t
*
p_sys
=
malloc
(
sizeof
(
*
p_sys
)
+
i_alloc
);
if
(
p_sys
==
NULL
)
...
...
@@ -88,7 +94,9 @@ block_t *block_Alloc( size_t i_size )
p_sys
->
i_allocated_buffer
=
i_alloc
;
block_Init
(
&
p_sys
->
self
,
p_sys
->
p_allocated_buffer
+
BLOCK_PADDING_SIZE
+
16
-
((
uintptr_t
)
p_sys
->
p_allocated_buffer
%
16
),
i_size
);
+
BLOCK_ALIGN
-
((
uintptr_t
)
p_sys
->
p_allocated_buffer
%
BLOCK_ALIGN
),
i_size
);
p_sys
->
self
.
pf_release
=
BlockRelease
;
return
&
p_sys
->
self
;
...
...
@@ -161,6 +169,24 @@ block_t *block_Realloc( block_t *p_block, ssize_t i_prebody, size_t i_body )
return
p_rea
;
}
/* We have a very large reserved footer now? Release some of it. */
if
((
p_sys
->
p_allocated_buffer
+
p_sys
->
i_allocated_buffer
)
-
(
p_block
->
p_buffer
+
p_block
->
i_buffer
)
>
BLOCK_WASTE_SIZE
)
{
const
size_t
news
=
p_block
->
i_buffer
+
2
*
BLOCK_PADDING_SIZE
+
16
;
block_sys_t
*
newb
=
realloc
(
p_sys
,
sizeof
(
*
p_sys
)
+
news
);
if
(
newb
!=
NULL
)
{
p_sys
=
newb
;
p_sys
->
i_allocated_buffer
=
news
;
p_block
=
&
p_sys
->
self
;
p_block
->
p_buffer
=
p_sys
->
p_allocated_buffer
+
BLOCK_PADDING_SIZE
+
BLOCK_ALIGN
-
((
uintptr_t
)
p_sys
->
p_allocated_buffer
%
BLOCK_ALIGN
);
}
}
return
p_block
;
}
...
...
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