From 21a4337dc2f969dc3ec81e6ba3170119bcb67016 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 22 Jul 2014 16:39:01 +0000 Subject: Deferred erase now works on cache entries. You can erase a cache entry while it still has active references, and it will be safely cleaned up when the last reference is released. --- src/stable/array.h | 24 ++++++++++++++++++++++++ src/stable/file.cpp | 9 +++++++-- src/stable/file.h | 4 ++++ 3 files changed, 35 insertions(+), 2 deletions(-) (limited to 'src/stable') diff --git a/src/stable/array.h b/src/stable/array.h index a598865..a662705 100644 --- a/src/stable/array.h +++ b/src/stable/array.h @@ -297,6 +297,30 @@ namespace Bu return core->iSize; } + void setSize( long iNewLen, const value &initTo=value() ) + { + if( core->iSize == iNewLen ) + return; + + _hardCopy(); + if( iNewLen > core->iCapacity ) + { + core->setCapacity( iNewLen ); + for( int j = core->iSize; j < iNewLen; j++ ) + { + core->va.construct( + &core->pData[j], + initTo + ); + } + core->iSize = iNewLen; + } + else + { + core->iSize = iNewLen; + } + } + /** * Get the capacity of the array. This number will grow as data is * added, and is mainly for the curious, it doesn't really determine diff --git a/src/stable/file.cpp b/src/stable/file.cpp index b551d24..35933f1 100644 --- a/src/stable/file.cpp +++ b/src/stable/file.cpp @@ -240,7 +240,7 @@ void Bu::File::setSize( Bu::size iSize ) Bu::size Bu::File::getSize() const { - struct stat st; + struct ::stat st; fstat( fd, &st ); return st.st_size; } @@ -250,7 +250,7 @@ Bu::size Bu::File::getBlockSize() const #ifdef WIN32 return 4096; #else - struct stat st; + struct ::stat st; fstat( fd, &st ); return st.st_blksize; #endif @@ -261,6 +261,11 @@ Bu::String Bu::File::getLocation() const return "to be implemented"; } +void Bu::File::stat( struct ::stat *pStat ) +{ + fstat( fd, pStat ); +} + #ifndef WIN32 void Bu::File::chmod( mode_t t ) { diff --git a/src/stable/file.h b/src/stable/file.h index ad60e80..e3497d3 100644 --- a/src/stable/file.h +++ b/src/stable/file.h @@ -15,6 +15,8 @@ #include "bu/string.h" #include "bu/exceptionbase.h" +struct stat; + namespace Bu { subExceptionDecl( FileException ); @@ -76,6 +78,8 @@ namespace Bu virtual size getBlockSize() const; virtual Bu::String getLocation() const; + void stat( struct ::stat *pStat ); + /** * Create a temp file and return its handle. The file is opened * Read/Write. -- cgit v1.2.3