diff --git a/_byte_buffer_8cpp.html b/_byte_buffer_8cpp.html index f558f1b0..97724a96 100644 --- a/_byte_buffer_8cpp.html +++ b/_byte_buffer_8cpp.html @@ -93,6 +93,7 @@ $(function(){ initResizable(false); });
#include "ByteBuffer.h"
+#include <iostream>

Go to the source code of this file.

diff --git a/_byte_buffer_8cpp_source.html b/_byte_buffer_8cpp_source.html index af7144a6..67da3f9e 100644 --- a/_byte_buffer_8cpp_source.html +++ b/_byte_buffer_8cpp_source.html @@ -93,106 +93,119 @@ $(function(){ initResizable(false); });
Go to the documentation of this file.
1#include "ByteBuffer.h"
-
2
-
- -
4 : content(NULL), contentSize(v_size), padding(v_padding),
-
5 originalSize(v_size)
-
6{
-
7 if (v_size == 0) throw BufferException("Zero size requested");
-
8
-
9 this->content = allocContent(v_size, v_padding);
-
10 this->contentSize = v_size;
-
11}
+
2#include <iostream>
+
3
+
+ +
5 : content(nullptr), contentSize(0), padding(v_padding),
+ +
7{
+
8 if (v_size == 0) throw BufferException("Zero size requested");
+
9
+
10 this->content = allocContent(v_size, v_padding);
+
11 this->contentSize = v_size;
+
12 this->originalSize = v_size;
+
13}
-
12
-
-
13ByteBuffer::ByteBuffer(BYTE *v_content, bufsize_t v_size, bufsize_t v_padding)
-
14 : content(NULL), contentSize(v_size), padding(v_padding),
-
15 originalSize(v_size)
-
16{
-
17 if (v_size == 0) throw BufferException("Zero size requested");
-
18
-
19 this->content = allocContent(v_size, v_padding);
-
20 this->contentSize = v_size;
-
21 ::memcpy(this->content, v_content, v_size);
-
22}
+
14
+
+
15ByteBuffer::ByteBuffer(BYTE *v_content, bufsize_t v_size, bufsize_t v_padding)
+
16 : content(nullptr), contentSize(0), padding(v_padding),
+ +
18{
+
19 if (v_size == 0) throw BufferException("Zero size requested");
+
20
+
21 this->content = allocContent(v_size, v_padding);
+
22 if (this->content) {
+
23 this->contentSize = v_size;
+
24 this->originalSize = v_size;
+
25 ::memcpy(this->content, v_content, v_size);
+
26 }
+
27}
-
23
-
- -
25 : content(NULL), contentSize(0), padding(0),
- -
27{
-
28 if (v_parent == NULL) throw BufferException("Cannot make subBuffer for NULL buffer!");
-
29 if (v_size == 0) throw BufferException("Cannot make 0 size buffer!");
-
30
-
31 bufsize_t parentSize = v_parent->getContentSize();
-
32
-
33 bufsize_t copySize = v_size < parentSize ? v_size : parentSize;
-
34 bufsize_t allocSize = v_size > parentSize ? v_size : parentSize;
+
28
+
+ +
30 : content(NULL), contentSize(0), padding(0),
+ +
32{
+
33 if (!v_parent) throw BufferException("Cannot make subBuffer for NULL buffer!");
+
34 if (!v_size) throw BufferException("Cannot make 0 size buffer!");
35
-
36 BYTE *bContent = v_parent->getContentAt(v_offset, copySize);
-
37 if (bContent == NULL) throw BufferException("Cannot make Buffer for NULL content!");
-
38
-
39 this->content = allocContent(allocSize, v_padding);
-
40 this->contentSize = allocSize;
-
41 this->originalSize = this->contentSize;
-
42 ::memcpy(this->content, bContent, copySize);
-
43}
+
36 bufsize_t parentSize = v_parent->getContentSize();
+
37
+
38 bufsize_t copySize = v_size < parentSize ? v_size : parentSize;
+
39 bufsize_t allocSize = v_size > parentSize ? v_size : parentSize;
+
40
+
41 BYTE *bContent = v_parent->getContentAt(v_offset, copySize);
+
42 if (!bContent) throw BufferException("Cannot make Buffer for NULL content!");
+
43
+
44 this->content = allocContent(allocSize, v_padding);
+
45 if (this->content) {
+
46 this->contentSize = allocSize;
+
47 this->originalSize = this->contentSize;
+
48 ::memcpy(this->content, bContent, copySize);
+
49 }
+
50}
-
44
-
- -
46{
-
47 if (v_size == 0) throw BufferException("Zero size requested");
-
48 bufsize_t allocSize = v_size + v_padding;
-
49 BYTE* content = new (std::nothrow) BYTE[allocSize];
-
50 if (content == NULL) {
-
51 throw BufferException("Cannot allocate buffer of size: 0x" + QString::number(allocSize, 16));
-
52 }
-
53 ::memset(content, 0, allocSize);
-
54 return content;
-
55}
+
51
+
+ +
53{
+
54 if (!v_size) throw BufferException("Zero size requested");
+
55
+
56 const bufsize_t allocSize = v_size + v_padding;
+
57 std::cerr << "Trying to resize. Ptr: " << std::hex << (void*)content << " New size: " << allocSize << std::endl;
+
58
+
59 const bufsize_t sizeDiff = (allocSize > this->contentSize) ? (allocSize - this->contentSize) : 0;
+
60 BYTE* content = reinterpret_cast<BYTE*>(::realloc((void*)this->content, allocSize));
+
61
+
62 if (!content) {
+
63 std::cerr << "Error!" << std::endl;
+
64 throw BufferException("Cannot allocate buffer of size: 0x" + QString::number(allocSize, 16));
+
65 }
+
66 if (sizeDiff) {
+
67 std::cerr << "Ptr: " << std::hex << (void*)content << " Additional size: " << sizeDiff << " BaseContentSize: " << this->contentSize << std::endl;
+
68 ::memset(content + this->contentSize, 0, sizeDiff);
+
69 } else {
+
70 std::cerr << "Ptr: " << std::hex << (void*)content << " New size: " << allocSize << std::endl;
+
71 }
+
72 /*if (sizeDiff) {
+
73 // if some memory has been added to the existing buffer, initialize it with 0
+
74 ::memset(content + this->contentSize, 0, sizeDiff);
+
75 }*/
+
76 return content;
+
77}
-
56
-
- -
58{
-
59 if (newSize == this->contentSize) return true;
-
60
-
61 BYTE *newContent = NULL;
-
62 try {
-
63 newContent = allocContent(newSize, this->padding);
-
64 } catch(BufferException) {
-
65 newContent = NULL;
-
66 }
-
67 if (!newContent) return false;
-
68
-
69 BYTE *oldContent = this->content;
-
70 bufsize_t oldSize = this->contentSize;
-
71 bufsize_t copySize = newSize < oldSize ? newSize : oldSize;
-
72
-
73 ::memcpy(newContent, oldContent, copySize);
-
74
-
75 this->content = newContent;
-
76 this->contentSize = newSize;
-
77
-
78 delete []oldContent;
-
79
-
80 return true;
-
81}
+
78
+
+ +
80{
+
81 if (newSize == this->contentSize) {
+
82 return true;
+
83 }
+
84 BYTE *newContent = nullptr;
+
85 bool isOk = true;
+
86 try {
+
87 newContent = allocContent(newSize, this->padding);
+
88 if (newContent) {
+
89 this->content = newContent;
+
90 this->contentSize = newSize;
+
91 }
+
92 } catch (BufferException &e) {
+
93 isOk = false;
+
94 }
+
95 return isOk;
+
96}
-
82
-
- -
84{
-
85 delete []this->content;
-
86}
+
97
+
+ +
99{
+
100 std::cerr << "Ptr: " << std::hex << (void*)content << " BaseContentSize: " << this->contentSize << " : " << __FUNCTION__ << std::endl;
+
101 ::free(this->content);
+
102}
-
87
-
88
-
89
uint32_t bufsize_t
uint64_t offset_t
@@ -202,12 +215,12 @@ $(function(){ initResizable(false); });
bufsize_t originalSize
Definition ByteBuffer.h:28
BYTE * content
Definition ByteBuffer.h:24
-
virtual ~ByteBuffer()
+
virtual ~ByteBuffer()
bufsize_t contentSize
Definition ByteBuffer.h:25
-
ByteBuffer(bufsize_t v_size, bufsize_t padding=DEFAULT_PADDING)
Definition ByteBuffer.cpp:3
-
BYTE * allocContent(bufsize_t v_size, bufsize_t padding)
+
ByteBuffer(bufsize_t v_size, bufsize_t padding=DEFAULT_PADDING)
Definition ByteBuffer.cpp:4
+
BYTE * allocContent(bufsize_t v_size, bufsize_t padding)
bufsize_t padding
Definition ByteBuffer.h:26
-
virtual bool resize(bufsize_t newSize)
+
virtual bool resize(bufsize_t newSize)
-

Definition at line 3 of file ByteBuffer.cpp.

+

Definition at line 4 of file ByteBuffer.cpp.

Here is the call graph for this function:
@@ -255,7 +255,7 @@ Here is the call graph for this function:
-

Definition at line 13 of file ByteBuffer.cpp.

+

Definition at line 15 of file ByteBuffer.cpp.

Here is the call graph for this function:
@@ -298,7 +298,7 @@ Here is the call graph for this function:
-

Definition at line 24 of file ByteBuffer.cpp.

+

Definition at line 29 of file ByteBuffer.cpp.

Here is the call graph for this function:
@@ -344,7 +344,7 @@ Here is the call graph for this function:
-

Definition at line 83 of file ByteBuffer.cpp.

+

Definition at line 98 of file ByteBuffer.cpp.

@@ -376,7 +376,7 @@ Here is the call graph for this function:
-

Definition at line 45 of file ByteBuffer.cpp.

+

Definition at line 52 of file ByteBuffer.cpp.

@@ -492,7 +492,7 @@ Here is the call graph for this function:

Reimplemented from AbstractByteBuffer.

-

Definition at line 57 of file ByteBuffer.cpp.

+

Definition at line 79 of file ByteBuffer.cpp.

Here is the call graph for this function: