summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
39c7e66)
add method to discard everything before the current position
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include "GrowingBuffer.h"
GrowingBuffer::GrowingBuffer(size_t initialSize) {
#include "GrowingBuffer.h"
GrowingBuffer::GrowingBuffer(size_t initialSize) {
void* GrowingBuffer::read(void* buffer, size_t length) {
size_t bytesToCopy = (length > (limit - position)) ? (limit - position) : length;
void* GrowingBuffer::read(void* buffer, size_t length) {
size_t bytesToCopy = (length > (limit - position)) ? (limit - position) : length;
- memcpy(buffer, (char*) data + position, bytesToCopy);
+ memcpy(buffer, (ptrdiff_t*) data + position, bytesToCopy);
position += bytesToCopy;
return buffer;
}
position += bytesToCopy;
return buffer;
}
free(data);
data = newData;
}
free(data);
data = newData;
}
- memcpy((char*) data + position, buffer, length);
+ memcpy((ptrdiff_t*) data + position, buffer, length);
+}
+
+void GrowingBuffer::cut() {
+ memcpy(data, (ptrdiff_t*) data + position, position);
+ limit = position;
+ position = 0;
}
void GrowingBuffer::truncate() {
}
void GrowingBuffer::truncate() {
void seek(size_t position);
void* read(void* buffer, size_t length);
void write(const void* buffer, size_t length);
void seek(size_t position);
void* read(void* buffer, size_t length);
void write(const void* buffer, size_t length);
void truncate();
void clear();
void resize(double factor = 1.0);
void truncate();
void clear();
void resize(double factor = 1.0);