Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
aom-rav1e
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Raphael Zumer
aom-rav1e
Commits
73a3fd47
Commit
73a3fd47
authored
8 years ago
by
Urvang Joshi
Committed by
Yaowu Xu
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
aom_mem: Refactor code
Change-Id: I2da9cd5da48ae97e770bccfd1233bcc70b484688
parent
e14a42a4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aom_mem/aom_mem.c
+28
-27
28 additions, 27 deletions
aom_mem/aom_mem.c
with
28 additions
and
27 deletions
aom_mem/aom_mem.c
+
28
−
27
View file @
73a3fd47
...
...
@@ -18,35 +18,42 @@
#include
"include/aom_mem_intrnl.h"
#include
"aom/aom_integer.h"
void
*
aom_memalign
(
size_t
align
,
size_t
size
)
{
void
*
addr
,
*
x
=
NULL
;
static
inline
size_t
*
GetMallocAddressLocation
(
void
*
const
mem
)
{
return
((
size_t
*
)
mem
)
-
1
;
}
static
inline
void
SetActualMallocAddress
(
void
*
const
mem
,
const
void
*
const
malloc_addr
)
{
size_t
*
const
malloc_addr_location
=
GetMallocAddressLocation
(
mem
);
*
malloc_addr_location
=
(
size_t
)
malloc_addr
;
}
addr
=
malloc
(
size
+
align
-
1
+
ADDRESS_STORAGE_SIZE
);
static
inline
void
*
GetActualMallocAddress
(
void
*
const
mem
)
{
const
size_t
*
const
malloc_addr_location
=
GetMallocAddressLocation
(
mem
);
return
(
void
*
)(
*
malloc_addr_location
);
}
void
*
aom_memalign
(
size_t
align
,
size_t
size
)
{
void
*
x
=
NULL
;
void
*
const
addr
=
malloc
(
size
+
align
-
1
+
ADDRESS_STORAGE_SIZE
);
if
(
addr
)
{
x
=
align_addr
((
unsigned
char
*
)
addr
+
ADDRESS_STORAGE_SIZE
,
(
int
)
align
);
/* save the actual malloc address */
((
size_t
*
)
x
)[
-
1
]
=
(
size_t
)
addr
;
SetActualMallocAddress
(
x
,
addr
);
}
return
x
;
}
void
*
aom_malloc
(
size_t
size
)
{
return
aom_memalign
(
DEFAULT_ALIGNMENT
,
size
);
}
void
*
aom_calloc
(
size_t
num
,
size_t
size
)
{
void
*
x
;
x
=
aom_memalign
(
DEFAULT_ALIGNMENT
,
num
*
size
);
if
(
x
)
memset
(
x
,
0
,
num
*
size
);
const
size_t
total_size
=
num
*
size
;
void
*
const
x
=
aom_malloc
(
total_size
);
if
(
x
)
memset
(
x
,
0
,
total_size
);
return
x
;
}
void
*
aom_realloc
(
void
*
memblk
,
size_t
size
)
{
void
*
addr
,
*
new_addr
=
NULL
;
int
align
=
DEFAULT_ALIGNMENT
;
void
*
new_addr
=
NULL
;
/*
The realloc() function changes the size of the object pointed to by
...
...
@@ -61,19 +68,13 @@ void *aom_realloc(void *memblk, size_t size) {
else
if
(
!
size
)
aom_free
(
memblk
);
else
{
addr
=
(
void
*
)(((
size_t
*
)
memblk
)
[
-
1
])
;
void
*
addr
=
GetActualMallocAddress
(
memblk
);
memblk
=
NULL
;
new_addr
=
realloc
(
addr
,
size
+
align
+
ADDRESS_STORAGE_SIZE
);
if
(
new_addr
)
{
addr
=
new_addr
;
new_addr
=
(
void
*
)(((
size_t
)((
unsigned
char
*
)
new_addr
+
ADDRESS_STORAGE_SIZE
)
+
(
align
-
1
))
&
(
size_t
)
-
align
);
/* save the actual malloc address */
((
size_t
*
)
new_addr
)[
-
1
]
=
(
size_t
)
addr
;
addr
=
realloc
(
addr
,
size
+
DEFAULT_ALIGNMENT
+
ADDRESS_STORAGE_SIZE
);
if
(
addr
)
{
new_addr
=
align_addr
((
unsigned
char
*
)
addr
+
ADDRESS_STORAGE_SIZE
,
DEFAULT_ALIGNMENT
);
SetActualMallocAddress
(
new_addr
,
addr
);
}
}
...
...
@@ -82,7 +83,7 @@ void *aom_realloc(void *memblk, size_t size) {
void
aom_free
(
void
*
memblk
)
{
if
(
memblk
)
{
void
*
addr
=
(
void
*
)(((
size_t
*
)
memblk
)
[
-
1
])
;
void
*
addr
=
GetActualMallocAddress
(
memblk
);
free
(
addr
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment