Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
openfpm_devices
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sbalzarini Lab
Software
Parallel Computing
OpenFPM
openfpm_devices
Commits
f46e3123
Commit
f46e3123
authored
8 years ago
by
Pietro Incardona
Browse files
Options
Downloads
Patches
Plain Diff
Small fix on BHeapMemory
parent
ddece6ce
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/memory/BHeapMemory.hpp
+14
-0
14 additions, 0 deletions
src/memory/BHeapMemory.hpp
src/memory/HeapMemory.hpp
+32
-0
32 additions, 0 deletions
src/memory/HeapMemory.hpp
src/memory/HeapMemory_unit_tests.hpp
+44
-0
44 additions, 0 deletions
src/memory/HeapMemory_unit_tests.hpp
with
90 additions
and
0 deletions
src/memory/BHeapMemory.hpp
+
14
−
0
View file @
f46e3123
...
...
@@ -166,6 +166,20 @@ public:
HeapMemory
::
destroy
();
buf_sz
=
0
;
}
/*! \brief swap the two mwmory object
*
* \param mem Memory to swap with
*
*/
void
swap
(
BHeapMemory
&
mem
)
{
HeapMemory
::
swap
(
mem
);
size_t
buf_sz_t
=
mem
.
buf_sz
;
mem
.
buf_sz
=
buf_sz
;
buf_sz
=
buf_sz_t
;
}
};
...
...
This diff is collapsed.
Click to expand it.
src/memory/HeapMemory.hpp
+
32
−
0
View file @
f46e3123
...
...
@@ -145,6 +145,38 @@ public:
else
std
::
cerr
<<
"Error: "
<<
__FILE__
<<
" "
<<
__LINE__
<<
" destroying a live object"
<<
"
\n
"
;
};
/*! \brief Swap the memory
*
* \param mem memory to swap
*
*/
void
swap
(
HeapMemory
&
mem
)
{
size_t
alignement_tmp
;
size_t
sz_tmp
;
byte
*
dm_tmp
;
byte
*
dmOrig_tmp
;
long
int
ref_cnt_tmp
;
alignement_tmp
=
alignement
;
sz_tmp
=
sz
;
dm_tmp
=
dm
;
dmOrig_tmp
=
dmOrig
;
ref_cnt_tmp
=
ref_cnt
;
alignement
=
mem
.
alignement
;
sz
=
mem
.
sz
;
dm
=
mem
.
dm
;
dmOrig
=
mem
.
dmOrig
;
ref_cnt
=
mem
.
ref_cnt
;
mem
.
alignement
=
alignement_tmp
;
mem
.
sz
=
sz_tmp
;
mem
.
dm
=
dm_tmp
;
mem
.
dmOrig
=
dmOrig_tmp
;
mem
.
ref_cnt
=
ref_cnt_tmp
;
}
};
...
...
This diff is collapsed.
Click to expand it.
src/memory/HeapMemory_unit_tests.hpp
+
44
−
0
View file @
f46e3123
...
...
@@ -174,6 +174,45 @@ template<typename T> void Btest()
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
FIRST_ALLOCATION
);
}
template
<
typename
T
>
void
Stest
()
{
T
mem1
;
T
mem2
;
mem1
.
allocate
(
5
*
sizeof
(
size_t
));
mem2
.
allocate
(
6
*
sizeof
(
size_t
));
BOOST_REQUIRE_EQUAL
(
mem1
.
size
(),
5
*
sizeof
(
size_t
));
BOOST_REQUIRE_EQUAL
(
mem2
.
size
(),
6
*
sizeof
(
size_t
));
// get the pointer of the allocated memory and fill
size_t
*
ptr1
=
(
size_t
*
)
mem1
.
getPointer
();
size_t
*
ptr2
=
(
size_t
*
)
mem2
.
getPointer
();
for
(
size_t
i
=
0
;
i
<
5
;
i
++
)
ptr1
[
i
]
=
i
;
for
(
size_t
i
=
0
;
i
<
6
;
i
++
)
ptr2
[
i
]
=
i
+
100
;
mem1
.
swap
(
mem2
);
bool
ret
=
true
;
ptr1
=
(
size_t
*
)
mem2
.
getPointer
();
ptr2
=
(
size_t
*
)
mem1
.
getPointer
();
for
(
size_t
i
=
0
;
i
<
5
;
i
++
)
ret
&=
ptr1
[
i
]
==
i
;
for
(
size_t
i
=
0
;
i
<
6
;
i
++
)
ret
&=
ptr2
[
i
]
==
i
+
100
;
BOOST_REQUIRE_EQUAL
(
ret
,
true
);
BOOST_REQUIRE_EQUAL
(
mem1
.
size
(),
6
*
sizeof
(
size_t
));
BOOST_REQUIRE_EQUAL
(
mem2
.
size
(),
5
*
sizeof
(
size_t
));
}
BOOST_AUTO_TEST_CASE
(
use_heap_memory
)
{
test
<
HeapMemory
>
();
...
...
@@ -195,6 +234,11 @@ BOOST_AUTO_TEST_CASE( use_bheap_memory )
Btest
<
BHeapMemory
>
();
}
BOOST_AUTO_TEST_CASE
(
swap_heap_memory
)
{
Stest
<
HeapMemory
>
();
}
BOOST_AUTO_TEST_SUITE_END
()
...
...
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