Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
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
cpp-libs
Actor Framework
Commits
6e466116
Commit
6e466116
authored
May 10, 2014
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed memory leak in memory_cache
parent
0b62812c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
8 deletions
+7
-8
cppa/detail/memory.hpp
cppa/detail/memory.hpp
+7
-8
No files found.
cppa/detail/memory.hpp
View file @
6e466116
...
@@ -122,6 +122,9 @@ class memory {
...
@@ -122,6 +122,9 @@ class memory {
template
<
typename
T
>
template
<
typename
T
>
class
basic_memory_cache
:
public
memory_cache
{
class
basic_memory_cache
:
public
memory_cache
{
static
constexpr
size_t
ne
=
s_alloc_size
/
sizeof
(
T
);
static
constexpr
size_t
dsize
=
ne
>
s_min_elements
?
ne
:
s_min_elements
;
struct
wrapper
:
instance_wrapper
{
struct
wrapper
:
instance_wrapper
{
ref_counted
*
parent
;
ref_counted
*
parent
;
union
{
T
instance
;
};
union
{
T
instance
;
};
...
@@ -133,8 +136,6 @@ class basic_memory_cache : public memory_cache {
...
@@ -133,8 +136,6 @@ class basic_memory_cache : public memory_cache {
class
storage
:
public
ref_counted
{
class
storage
:
public
ref_counted
{
static
constexpr
size_t
ne
=
s_alloc_size
/
sizeof
(
T
);
static
constexpr
size_t
dsize
=
ne
>
s_min_elements
?
ne
:
s_min_elements
;
public:
public:
...
@@ -163,7 +164,7 @@ class basic_memory_cache : public memory_cache {
...
@@ -163,7 +164,7 @@ class basic_memory_cache : public memory_cache {
std
::
vector
<
wrapper
*>
cached_elements
;
std
::
vector
<
wrapper
*>
cached_elements
;
basic_memory_cache
()
{
basic_memory_cache
()
{
cached_elements
.
reserve
(
s_cache_size
/
sizeof
(
T
)
);
cached_elements
.
reserve
(
dsize
);
}
}
~
basic_memory_cache
()
{
~
basic_memory_cache
()
{
...
@@ -174,18 +175,16 @@ class basic_memory_cache : public memory_cache {
...
@@ -174,18 +175,16 @@ class basic_memory_cache : public memory_cache {
return
static_cast
<
T
*>
(
ptr
);
return
static_cast
<
T
*>
(
ptr
);
}
}
void
release_instance
(
void
*
vptr
)
override
{
virtual
void
release_instance
(
void
*
vptr
)
{
CPPA_REQUIRE
(
vptr
!=
nullptr
);
CPPA_REQUIRE
(
vptr
!=
nullptr
);
auto
ptr
=
reinterpret_cast
<
T
*>
(
vptr
);
auto
ptr
=
reinterpret_cast
<
T
*>
(
vptr
);
CPPA_REQUIRE
(
ptr
->
outer_memory
!=
nullptr
);
CPPA_REQUIRE
(
ptr
->
outer_memory
!=
nullptr
);
auto
wptr
=
static_cast
<
wrapper
*>
(
ptr
->
outer_memory
);
auto
wptr
=
static_cast
<
wrapper
*>
(
ptr
->
outer_memory
);
wptr
->
destroy
();
wptr
->
destroy
();
if
(
cached_elements
.
capacity
()
>
0
)
cached_elements
.
push_back
(
wptr
);
wptr
->
deallocate
();
else
wptr
->
deallocate
();
}
}
virtual
std
::
pair
<
instance_wrapper
*
,
void
*>
new_instance
()
{
std
::
pair
<
instance_wrapper
*
,
void
*>
new_instance
()
override
{
if
(
cached_elements
.
empty
())
{
if
(
cached_elements
.
empty
())
{
auto
elements
=
new
storage
;
auto
elements
=
new
storage
;
for
(
auto
i
=
elements
->
begin
();
i
!=
elements
->
end
();
++
i
)
{
for
(
auto
i
=
elements
->
begin
();
i
!=
elements
->
end
();
++
i
)
{
...
...
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