More optimization for Message2. It now uses a more lightweight BSimpleMallocIO instead of the full blown BMallocIO. This wastes less memory and reduces unnecessary overhead when unflattening.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13861 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2005-07-31 11:48:38 +00:00
parent 4835f2d292
commit 43abf8a345
7 changed files with 197 additions and 126 deletions
+88
View File
@@ -0,0 +1,88 @@
/*
* Copyright 2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Lotz <[email protected]>
*/
/* A BMallocIO similar structure but with less overhead */
#ifndef _SIMPLE_MALLOC_IO_H_
#define _SIMPLE_MALLOC_IO_H_
#include <malloc.h>
namespace BPrivate {
class BSimpleMallocIO {
public:
BSimpleMallocIO(size_t size)
: fSize(size)
{
fBuffer = (char *)malloc(size);
}
~BSimpleMallocIO()
{
free(fBuffer);
}
void Read(void *buffer)
{
memcpy(buffer, fBuffer, fSize);
}
void Read(void *buffer, size_t size)
{
memcpy(buffer, fBuffer, size);
}
void ReadAt(off_t pos, void *buffer, size_t size)
{
memcpy(buffer, fBuffer + pos, size);
}
void Write(const void *buffer)
{
memcpy(fBuffer, buffer, fSize);
}
void Write(const void *buffer, size_t size)
{
memcpy(fBuffer, buffer, size);
}
void WriteAt(off_t pos, const void *buffer, size_t size)
{
memcpy(fBuffer + pos, buffer, size);
}
status_t SetSize(off_t size)
{
fBuffer = (char *)realloc(fBuffer, size);
if (!fBuffer)
return B_NO_MEMORY;
fSize = size;
return B_OK;
}
char *Buffer()
{
return fBuffer;
}
size_t BufferLength()
{
return fSize;
}
private:
char *fBuffer;
size_t fSize;
};
} // namespace BPivate
#endif // _SIMPLE_MALLOC_IO_H_