Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
952ae5c5
Commit
952ae5c5
authored
Mar 05, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove byte/word default constructors and rely on calloc for zero-initialization.
parent
edad34c4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
7 deletions
+11
-7
message.c++
c++/src/capnproto/message.c++
+9
-5
type-safety.h
c++/src/capnproto/type-safety.h
+2
-2
No files found.
c++/src/capnproto/message.c++
View file @
952ae5c5
...
...
@@ -25,6 +25,7 @@
#include <vector>
#include <string.h>
#include <iostream>
#include <stdlib.h>
namespace
capnproto
{
...
...
@@ -45,12 +46,16 @@ public:
private
:
WordCount
preferredSegmentSize
;
std
::
vector
<
std
::
unique_ptr
<
SegmentBuilder
>>
segments
;
std
::
vector
<
std
::
unique_ptr
<
word
[]
>
>
memory
;
std
::
vector
<
word
*
>
memory
;
};
MallocMessage
::
MallocMessage
(
WordCount
preferredSegmentSize
)
:
preferredSegmentSize
(
preferredSegmentSize
)
{}
MallocMessage
::~
MallocMessage
()
{}
MallocMessage
::~
MallocMessage
()
{
for
(
word
*
ptr
:
memory
)
{
free
(
ptr
);
}
}
SegmentReader
*
MallocMessage
::
tryGetSegment
(
SegmentId
id
)
{
if
(
id
.
value
>=
segments
.
size
())
{
...
...
@@ -77,10 +82,9 @@ SegmentBuilder* MallocMessage::getSegment(SegmentId id) {
SegmentBuilder
*
MallocMessage
::
getSegmentWithAvailable
(
WordCount
minimumAvailable
)
{
if
(
segments
.
empty
()
||
segments
.
back
()
->
available
()
<
minimumAvailable
)
{
WordCount
newSize
=
std
::
max
(
minimumAvailable
,
preferredSegmentSize
);
memory
.
push_back
(
std
::
unique_ptr
<
word
[]
>
(
new
word
[
newSize
/
WORDS
]));
memset
(
memory
.
back
().
get
(),
0
,
newSize
/
WORDS
*
sizeof
(
word
));
memory
.
push_back
(
reinterpret_cast
<
word
*>
(
calloc
(
newSize
/
WORDS
,
sizeof
(
word
))));
segments
.
push_back
(
std
::
unique_ptr
<
SegmentBuilder
>
(
new
SegmentBuilder
(
this
,
SegmentId
(
segments
.
size
()),
memory
.
back
()
.
get
()
,
newSize
)));
this
,
SegmentId
(
segments
.
size
()),
memory
.
back
(),
newSize
)));
}
return
segments
.
back
().
get
();
}
...
...
c++/src/capnproto/type-safety.h
View file @
952ae5c5
...
...
@@ -317,8 +317,8 @@ inline constexpr auto operator*(UnitRatio<Number1, Unit2, Unit> ratio,
// =======================================================================================
// Raw memory types and measures
class
byte
{
uint8_t
content
;
CAPNPROTO_DISALLOW_COPY
(
byte
);
public
:
byte
()
=
default
;
};
class
word
{
uint64_t
content
;
CAPNPROTO_DISALLOW_COPY
(
word
);
public
:
word
()
=
default
;
};
class
byte
{
uint8_t
content
;
CAPNPROTO_DISALLOW_COPY
(
byte
);
};
class
word
{
uint64_t
content
;
CAPNPROTO_DISALLOW_COPY
(
word
);
};
// byte and word are opaque types with sizes of 8 and 64 bits, respectively. These types are useful
// only to make pointer arithmetic clearer. Since the contents are private, the only way to access
// them is to first reinterpret_cast to some other pointer type.
...
...
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