Fatal in <TBufferFile::WriteFastArray>: Not enough space left in the buffer (1GB limit). 4952997 elements is greater than the max left of 956626 aborting

In writing a large TTree to a file, my code produces this error message:

Fatal in <TBufferFile::WriteFastArray>: Not enough space left in the buffer (1GB limit). 4952997 elements is greater than the max left of 956626 aborting

A quick search told me that this is a hard limit, which I cannot really get around. That’s fine, but is there anyway to tell when I’m approaching that limit? That is something like:

if (myTTree->GetRemainingBuffer() <= someLimit) 
  {
    closeTFileAndCreateNewOne();
  }

Where GetRemainingBuffer() tells me how much space is left in the buffer? If this is a file or branch limit, a similar way to test those?

ROOT Version: 6.32.06
Platform: macosx
Compiler: Apple clang version 16.0.0 (clang-1600.0.26.4)

  TBufferFile b(TBuffer::kWrite, 10000);
   TTree::Class()->WriteBuffer(b, myTTree);
  and check: b.Length();

Another option is to go through all the branches and count the number of baskets created so far as the limit is roughly 50 millions baskets.