Skip to content
Snippets Groups Projects
Commit b35b5401 authored by Danilo Piparo's avatar Danilo Piparo
Browse files

[IO] Allow to set the size of the memory blocks

parent aaa1c34b
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,8 @@ private: ...@@ -45,7 +45,8 @@ private:
TMemBlock *fBlockSeek; ///< Pointer to the block we seeked to. TMemBlock *fBlockSeek; ///< Pointer to the block we seeked to.
Long64_t fBlockOffset; ///< Seek offset within the block Long64_t fBlockOffset; ///< Seek offset within the block
static Long64_t fgDefaultBlockSize; constexpr static Long64_t fgDefaultBlockSize = 2 * 1024 * 1024;
Long64_t fDefaultBlockSize = fgDefaultBlockSize;
Long64_t MemRead(Int_t fd, void *buf, Long64_t len) const; Long64_t MemRead(Int_t fd, void *buf, Long64_t len) const;
...@@ -77,7 +78,8 @@ private: ...@@ -77,7 +78,8 @@ private:
TMemFile &operator=(const TMemFile&); // Not implemented. TMemFile &operator=(const TMemFile&); // Not implemented.
public: public:
TMemFile(const char *name, Option_t *option="", const char *ftitle="", Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose); TMemFile(const char *name, Option_t *option = "", const char *ftitle = "",
Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Long64_t defBlockSize = 0LL);
TMemFile(const char *name, char *buffer, Long64_t size, Option_t *option="", const char *ftitle="", Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose); TMemFile(const char *name, char *buffer, Long64_t size, Option_t *option="", const char *ftitle="", Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose);
TMemFile(const char *name, ExternalDataPtr_t data); TMemFile(const char *name, ExternalDataPtr_t data);
TMemFile(const TMemFile &orig); TMemFile(const TMemFile &orig);
......
...@@ -40,8 +40,6 @@ only from memory. ...@@ -40,8 +40,6 @@ only from memory.
ClassImp(TMemFile); ClassImp(TMemFile);
Long64_t TMemFile::fgDefaultBlockSize = 2*1024*1024;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// Default constructor. /// Default constructor.
...@@ -137,19 +135,24 @@ TMemFile::TMemFile(const char *path, ExternalDataPtr_t data) : ...@@ -137,19 +135,24 @@ TMemFile::TMemFile(const char *path, ExternalDataPtr_t data) :
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// Usual Constructor. See the TFile constructor for details. /// \brief Usual Constructor.
/// The defBlockSize parameter defines the size of the blocks of memory allocated
TMemFile::TMemFile(const char *path, Option_t *option, /// when expanding the underlying TMemFileBuffer. If the value 0 is passed, the
const char *ftitle, Int_t compress) : /// default block size, fgDefaultBlockSize, is adopted.
TMemFile(path, nullptr, -1, option, ftitle, compress) {} /// See the TFile constructor for details.
TMemFile::TMemFile(const char *path, Option_t *option, const char *ftitle, Int_t compress, Long64_t defBlockSize)
: TMemFile(path, nullptr, -1, option, ftitle, compress)
{
fDefaultBlockSize = defBlockSize == 0LL ? fgDefaultBlockSize : defBlockSize;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// Usual Constructor. See the TFile constructor for details. Copy data from buffer. /// Usual Constructor. See the TFile constructor for details. Copy data from buffer.
TMemFile::TMemFile(const char *path, char *buffer, Long64_t size, Option_t *option, TMemFile::TMemFile(const char *path, char *buffer, Long64_t size, Option_t *option, const char *ftitle, Int_t compress)
const char *ftitle, Int_t compress): : TFile(path, "WEB", ftitle, compress), fBlockList(size), fSize(size), fSysOffset(0), fBlockSeek(&(fBlockList)),
TFile(path, "WEB", ftitle, compress), fBlockList(size), fBlockOffset(0)
fSize(size), fSysOffset(0), fBlockSeek(&(fBlockList)), fBlockOffset(0)
{ {
EMode optmode = ParseOption(option); EMode optmode = ParseOption(option);
...@@ -551,9 +554,9 @@ Long64_t TMemFile::SysSeek(Int_t, Long64_t offset, Int_t whence) ...@@ -551,9 +554,9 @@ Long64_t TMemFile::SysSeek(Int_t, Long64_t offset, Int_t whence)
Int_t TMemFile::SysOpen(const char * /* pathname */, Int_t /* flags */, UInt_t /* mode */) Int_t TMemFile::SysOpen(const char * /* pathname */, Int_t /* flags */, UInt_t /* mode */)
{ {
if (!fBlockList.fBuffer) { if (!fBlockList.fBuffer) {
fBlockList.fBuffer = new UChar_t[fgDefaultBlockSize]; fBlockList.fBuffer = new UChar_t[fDefaultBlockSize];
fBlockList.fSize = fgDefaultBlockSize; fBlockList.fSize = fDefaultBlockSize;
fSize = fgDefaultBlockSize; fSize = fDefaultBlockSize;
} }
if (fBlockList.fBuffer) { if (fBlockList.fBuffer) {
return 0; return 0;
...@@ -604,8 +607,8 @@ Int_t TMemFile::SysWriteImpl(Int_t /* fd */, const void *buf, Long64_t len) ...@@ -604,8 +607,8 @@ Int_t TMemFile::SysWriteImpl(Int_t /* fd */, const void *buf, Long64_t len)
buf = (char*)buf + sublen; buf = (char*)buf + sublen;
Int_t len_left = len - sublen; Int_t len_left = len - sublen;
if (!fBlockSeek->fNext) { if (!fBlockSeek->fNext) {
fBlockSeek->CreateNext(fgDefaultBlockSize); fBlockSeek->CreateNext(fDefaultBlockSize);
fSize += fgDefaultBlockSize; fSize += fDefaultBlockSize;
} }
fBlockSeek = fBlockSeek->fNext; fBlockSeek = fBlockSeek->fNext;
...@@ -617,8 +620,8 @@ Int_t TMemFile::SysWriteImpl(Int_t /* fd */, const void *buf, Long64_t len) ...@@ -617,8 +620,8 @@ Int_t TMemFile::SysWriteImpl(Int_t /* fd */, const void *buf, Long64_t len)
buf = (char*)buf + fBlockSeek->fSize; buf = (char*)buf + fBlockSeek->fSize;
len_left -= fBlockSeek->fSize; len_left -= fBlockSeek->fSize;
if (!fBlockSeek->fNext) { if (!fBlockSeek->fNext) {
fBlockSeek->CreateNext(fgDefaultBlockSize); fBlockSeek->CreateNext(fDefaultBlockSize);
fSize += fgDefaultBlockSize; fSize += fDefaultBlockSize;
} }
fBlockSeek = fBlockSeek->fNext; fBlockSeek = fBlockSeek->fNext;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment