Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Service Desk
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
Nils-Arne Dreier
dune-common
Commits
fd024f37
Commit
fd024f37
authored
20 years ago
by
Markus Blatt
Browse files
Options
Downloads
Patches
Plain Diff
Removed bug. allocator wrote beyond allocated memory.
[[Imported from SVN: r1224]]
parent
4ea100ee
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/poolallocator.hh
+24
-8
24 additions, 8 deletions
common/poolallocator.hh
with
24 additions
and
8 deletions
common/poolallocator.hh
+
24
−
8
View file @
fd024f37
...
...
@@ -5,6 +5,7 @@
#define DUNE_COMMON_POOLALLOCATOR_HH
#include
"alignment.hh"
#include
<typeinfo>
namespace
Dune
{
...
...
@@ -49,8 +50,8 @@ namespace Dune
/**
* @brief The aligned size of the type.
*
* This size is bigger than sizeof of the type and multiple of
* the algnment requirement.
* This size is bigger than sizeof of the type and
a
multiple of
* the al
i
gnment requirement.
*/
alignedSize
=
(
sizeof
(
MemberType
)
%
AlignmentOf
<
MemberType
>::
value
==
0
)
?
sizeof
(
MemberType
)
:
...
...
@@ -72,6 +73,7 @@ namespace Dune
*/
elements
=
(
chunkSize
/
alignedSize
)
};
private
:
struct
Reference
{
...
...
@@ -98,6 +100,7 @@ namespace Dune
Chunk
()
{
unsigned
long
lmemory
=
reinterpret_cast
<
unsigned
long
>
(
chunk_
);
if
(
lmemory
%
AlignmentOf
<
MemberType
>::
value
!=
0
)
lmemory
=
(
lmemory
/
AlignmentOf
<
MemberType
>::
value
+
1
)
*
AlignmentOf
<
MemberType
>::
value
;
...
...
@@ -124,6 +127,9 @@ namespace Dune
*/
inline
void
free
(
void
*
o
);
inline
void
print
();
private
:
// Prevent Copying!
...
...
@@ -255,17 +261,16 @@ namespace Dune
template
<
class
T
,
int
S
>
inline
Pool
<
T
,
S
>::
Pool
()
{
head_
=
0
;
chunks_
=
0
;
}
:
head_
(
0
),
chunks_
(
0
)
{}
template
<
class
T
,
int
S
>
inline
Pool
<
T
,
S
>::~
Pool
()
{
// delete the allocated chunks.
Chunk
*
current
=
chunks_
;
while
(
current
)
while
(
current
!=
0
)
{
Chunk
*
tmp
=
current
;
current
=
current
->
next_
;
...
...
@@ -273,6 +278,17 @@ namespace Dune
}
}
template
<
class
T
,
int
S
>
inline
void
Pool
<
T
,
S
>::
print
()
{
Chunk
*
current
=
chunks_
;
while
(
current
)
{
std
::
cout
<<
current
<<
" "
;
current
=
current
->
next_
;
}
std
::
cout
<<
current
<<
" "
;
}
template
<
class
T
,
int
S
>
inline
void
Pool
<
T
,
S
>::
grow
()
{
...
...
@@ -281,7 +297,7 @@ namespace Dune
chunks_
=
newChunk
;
char
*
start
=
reinterpret_cast
<
char
*>
(
chunks_
->
memory_
);
char
*
last
=
&
start
[
elements
*
alignedSize
];
char
*
last
=
&
start
[
(
elements
-
1
)
*
alignedSize
];
for
(
char
*
element
=
start
;
element
<
last
;
element
+=
alignedSize
)
reinterpret_cast
<
Reference
*>
(
element
)
->
next_
...
...
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