Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
c3cfa18e
Commit
c3cfa18e
authored
Sep 21, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/HugeAllocator: add template class HugeArray
parent
b46835e1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
0 deletions
+108
-0
HugeAllocator.hxx
src/util/HugeAllocator.hxx
+108
-0
No files found.
src/util/HugeAllocator.hxx
View file @
c3cfa18e
...
...
@@ -177,4 +177,112 @@ public:
}
};
/**
* Automatic memory management for a dynamic array in "huge" memory.
*/
template
<
typename
T
>
class
HugeArray
{
typedef
WritableBuffer
<
T
>
Buffer
;
Buffer
buffer
{
nullptr
};
public
:
typedef
typename
Buffer
::
size_type
size_type
;
typedef
typename
Buffer
::
value_type
value_type
;
typedef
typename
Buffer
::
reference_type
reference
;
typedef
typename
Buffer
::
const_reference_type
const_reference
;
typedef
typename
Buffer
::
iterator
iterator
;
typedef
typename
Buffer
::
const_iterator
const_iterator
;
constexpr
HugeArray
()
=
default
;
explicit
HugeArray
(
size_type
_size
)
:
buffer
(
Buffer
::
FromVoidFloor
(
HugeAllocate
(
sizeof
(
value_type
)
*
_size
)))
{}
constexpr
HugeArray
(
HugeArray
&&
other
)
:
buffer
(
std
::
exchange
(
other
.
buffer
,
nullptr
))
{}
~
HugeArray
()
{
if
(
buffer
!=
nullptr
)
{
auto
v
=
buffer
.
ToVoid
();
HugeFree
(
v
.
data
,
v
.
size
);
}
}
HugeArray
&
operator
=
(
HugeArray
&&
other
)
{
std
::
swap
(
buffer
,
other
.
buffer
);
return
*
this
;
}
void
ForkCow
(
bool
enable
)
noexcept
{
auto
v
=
buffer
.
ToVoid
();
HugeForkCow
(
v
.
data
,
v
.
size
,
enable
);
}
void
Discard
()
noexcept
{
auto
v
=
buffer
.
ToVoid
();
HugeDiscard
(
v
.
data
,
v
.
size
);
}
constexpr
bool
operator
==
(
std
::
nullptr_t
)
const
{
return
buffer
==
nullptr
;
}
constexpr
bool
operator
!=
(
std
::
nullptr_t
)
const
{
return
buffer
!=
nullptr
;
}
/**
* Returns the number of allocated elements.
*/
constexpr
size_type
size
()
const
{
return
buffer
.
size
;
}
reference
front
()
{
return
buffer
.
front
();
}
const_reference
front
()
const
{
return
buffer
.
front
();
}
reference
back
()
{
return
buffer
.
back
();
}
const_reference
back
()
const
{
return
buffer
.
back
();
}
/**
* Returns one element. No bounds checking.
*/
reference
operator
[](
size_type
i
)
{
return
buffer
[
i
];
}
/**
* Returns one constant element. No bounds checking.
*/
const_reference
operator
[](
size_type
i
)
const
{
return
buffer
[
i
];
}
iterator
begin
()
{
return
buffer
.
begin
();
}
constexpr
const_iterator
begin
()
const
{
return
buffer
.
cbegin
();
}
iterator
end
()
{
return
buffer
.
end
();
}
constexpr
const_iterator
end
()
const
{
return
buffer
.
cend
();
}
};
#endif
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