[commit] r1275 - trunk/GME/Core
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Wed Apr 20 13:55:06 CDT 2011
Author: ksmyth
Date: Wed Apr 20 13:55:06 2011
New Revision: 1275
Log:
Get rid of vectors in BinAttrs to save another word off each (271764 Attrs in MetaGME-model+MetaGME=10MB saved)
Modified:
trunk/GME/Core/CoreBinFile.cpp
trunk/GME/Core/CoreBinFile.h
Modified: trunk/GME/Core/CoreBinFile.cpp
==============================================================================
--- trunk/GME/Core/CoreBinFile.cpp Wed Apr 20 12:42:02 2011 (r1274)
+++ trunk/GME/Core/CoreBinFile.cpp Wed Apr 20 13:55:06 2011 (r1275)
@@ -596,6 +596,25 @@
}
}
+void CCoreBinFile::read(unsigned char*& b, int& len)
+{
+ read(len);
+ ASSERT( len >= 0 );
+
+ b = (unsigned char*)malloc(len);
+ if (b == NULL) {
+ // KMS: could get here if the project is corrupt and len is incorrect
+ COMTHROW(E_OUTOFMEMORY);
+ }
+ if( len > 0 ) {
+ if (len > cifs_eof - cifs) {
+ HR_THROW(E_FILEOPEN);
+ }
+ memcpy(b, cifs, len);
+ cifs += len;
+ }
+}
+
void CCoreBinFile::read(CComBstrObj &ss)
{
int len;
@@ -628,6 +647,18 @@
ofs.write( (const char *) &b[0], len);
}
+void CCoreBinFile::write(const unsigned char* b, int len)
+{
+ ASSERT( ofs.is_open() );
+
+ ASSERT( len >= 0 );
+
+ write(len);
+
+ if( len > 0 )
+ ofs.write( (const char *) b, len);
+}
+
void CCoreBinFile::write(const CComBstrObj &ss)
{
ASSERT( ofs.is_open() );
Modified: trunk/GME/Core/CoreBinFile.h
==============================================================================
--- trunk/GME/Core/CoreBinFile.h Wed Apr 20 12:42:02 2011 (r1274)
+++ trunk/GME/Core/CoreBinFile.h Wed Apr 20 13:55:06 2011 (r1275)
@@ -117,7 +117,7 @@
#ifdef _DEBUG
int pad[5];
#else
- int pad[3];
+ int pad[2];
#endif
};
@@ -250,6 +250,7 @@
void read(double &a) { CoreBinFile_read(a, sizeof(double)); }
void read(CComBstrObj &a);
void read(bindata &a);
+ void read(unsigned char*& b, int& len);
void write(unsigned char a) { ofs.write((const char*)&a, sizeof(unsigned char)); }
void write(short a) { ofs.write((const char*)&a, sizeof(short)); }
@@ -258,6 +259,7 @@
void write(double a) { ofs.write((const char*)&a, sizeof(double)); }
void write(const CComBstrObj &a);
void write(const bindata &a);
+ void write(const unsigned char* a, int len);
// ------- Attribute
@@ -405,22 +407,61 @@
// --------------------------- BinAttr<VALTYPE_BINARY>
+template<class Type>
+struct free_deleter {
+ void operator()(Type* p) { free(p); }
+};
+
template<>
class BinAttr<VALTYPE_BINARY> : public BinAttrBase
{
public:
BinAttr() { }
- bindata a;
+ typedef std::unique_ptr<unsigned char, free_deleter<unsigned char> > ptr;
+ ptr a;
+ int len;
virtual valtype_type GetValType() const NOTHROW { return VALTYPE_BINARY; }
- virtual void Set(CCoreBinFile *binfile, VARIANT p)
- { ASSERT( binfile != NULL ); binfile->modified = true; CopyTo(p, a); }
+ virtual void Set(CCoreBinFile *binfile, VARIANT v)
+ {
+ ASSERT( binfile != NULL );
+ binfile->modified = true;
+ if( v.vt == (VT_I4 | VT_ARRAY) )
+ {
+ len = sizeof(long) * GetArrayLength(v);
+ a = ptr((unsigned char*) malloc(len));
+ CopyTo(v, (long*)a.get(), (long*)(a.get()) + len/sizeof(long));
+ }
+ else
+ {
+ if (GetArrayLength(v)==0)
+ {
+ len = 0;
+ }
+ else
+ {
+ len = GetArrayLength(v);
+ a = ptr((unsigned char*) malloc(len));
+ CopyTo(v, a.get(), a.get() + len);
+ }
+ }
+ }
- virtual void Get(CCoreBinFile *binfile, VARIANT *p) const { CopyTo(a, p); }
- virtual void Write(CCoreBinFile *binfile) const { binfile->write(a); }
- virtual void Read(CCoreBinFile *binfile) { binfile->read(a); }
- BinAttr(BinAttr<VALTYPE_BINARY>&& that) : BinAttrBase(that.attrid), a(std::move(that.a)) { }
+ virtual void Get(CCoreBinFile *binfile, VARIANT *p) const {
+ //if (len == 0) {
+ // unsigned char* pnull=NULL;
+ // CopyTo(pnull,pnull, p);
+ //} else
+ CopyTo(a.get(), a.get() + len, p);
+ }
+ virtual void Write(CCoreBinFile *binfile) const { binfile->write(a.get(), len); }
+ virtual void Read(CCoreBinFile *binfile) {
+ unsigned char* p;
+ binfile->read(p, len);
+ a = ptr(p);
+ }
+ BinAttr(BinAttr<VALTYPE_BINARY>&& that) : BinAttrBase(that.attrid), a(std::move(that.a)), len(len) { }
virtual void move(BinAttrUnion&& dest) {
new (&dest) BinAttr<VALTYPE_BINARY>(std::move(*this));
}
@@ -452,9 +493,11 @@
class BinAttr<VALTYPE_COLLECTION> : public BinAttrBase
{
public:
- std::vector<objects_iterator> a;
+ std::unique_ptr<std::vector<objects_iterator>> backing;
+ std::vector<objects_iterator>& getbacking() const { return *backing.get(); }
+ __declspec(property(get = getbacking )) std::vector<objects_iterator>& a;
- BinAttr() { }
+ BinAttr() : backing(new std::vector<objects_iterator>()) { }
virtual valtype_type GetValType() const NOTHROW { return VALTYPE_COLLECTION; }
virtual void Set(CCoreBinFile *binfile, VARIANT p) { ASSERT(false); }
virtual void Get(CCoreBinFile *binfile, VARIANT *p) const
@@ -476,9 +519,7 @@
}
virtual void Write(CCoreBinFile *binfile) const { }
virtual void Read(CCoreBinFile *binfile) { }
- // N3126 §23.2.1/9: Every iterator referring to an element in one container before the swap shall refer to the same element in the other container after the swap.
- // supposing this applies to std::move, BinAttr<VALTYPE_POINTER> iterator should remain valid
- BinAttr(BinAttr<VALTYPE_COLLECTION>&& that) : BinAttrBase(that.attrid), a(std::move(that.a)) { }
+ BinAttr(BinAttr<VALTYPE_COLLECTION>&& that) : BinAttrBase(that.attrid), backing(std::move(that.backing)) { }
virtual void move(BinAttrUnion&& dest) {
new (&dest) BinAttr<VALTYPE_COLLECTION>(std::move(*this));
}
More information about the gme-commit
mailing list