I would put this logic in the BulkInserter (so the CURVE_CACHE_SIZE becomes a field of this class, e.g.  query_string_size ). Then, every client of the BulkInserter can benefit of this guard that prevents too much extra memory to be consumed for a single bulk insert.