MemBuf.cc File Reference
#include "squid.h"
#include "mem/forward.h"
#include "MemBuf.h"
#include "profiler/Profiler.h"
Include dependency graph for MemBuf.cc:

Go to the source code of this file.

Macros

#define MEM_BUF_INIT_SIZE   (2*1024)
 
#define MEM_BUF_MAX_SIZE   (2*1000*1024*1024)
 

Functions

void memBufReport (MemBuf *mb)
 

Macro Definition Documentation

#define MEM_BUF_INIT_SIZE   (2*1024)
* Rationale:
* ----------
*
* Here is how one would Comm::Write an object without MemBuffer:
*
* {
* -- allocate:
* buf = malloc(big_enough);
*
* -- "pack":
* snprintf object(s) piece-by-piece constantly checking for overflows
* and maintaining (buf+offset);
* ...
*
* -- write
* Comm::Write(buf, free, ...);
* }
*
* The whole "packing" idea is quite messy: We are given a buffer of fixed
* size and we have to check all the time that we still fit. Sounds logical.
*
* However, what happens if we have more data? If we are lucky to stop before
* we overrun any buffers, we still may have garbage (e.g. half of ETag) in
* the buffer.
*
* MemBuffer:
* ----------
*
* MemBuffer is a memory-resident buffer with printf()-like interface. It
* hides all offest handling and overflow checking. Moreover, it has a
* build-in control that no partial data has been written.
*
* MemBuffer is designed to handle relatively small data. It starts with a
* small buffer of configurable size to avoid allocating huge buffers all the
* time.  MemBuffer doubles the buffer when needed. It assert()s that it will
* not grow larger than a configurable limit. MemBuffer has virtually no
* overhead (and can even reduce memory consumption) compared to old
* "packing" approach.
*
* MemBuffer eliminates both "packing" mess and truncated data:
*
* {
* -- setup
* MemBuf buf;
*
* -- required init with optional size tuning (see #defines for defaults)
* buf.init(initial-size, absolute-maximum);
*
* -- "pack" (no need to handle offsets or check for overflows)
* buf.Printf(...);
* ...
*
* -- write
* Comm::Write(fd, buf, callback);
*
* -- *iff* you did not give the buffer away, free it yourself
* -- buf.clean();
* }

Definition at line 91 of file MemBuf.cc.

Referenced by MemBuf::init().

#define MEM_BUF_MAX_SIZE   (2*1000*1024*1024)

Definition at line 92 of file MemBuf.cc.

Referenced by MemBuf::init().

Function Documentation

void memBufReport ( MemBuf mb)

Puts report on MemBuf module usage into mb

Definition at line 387 of file MemBuf.cc.

References Packable::appendf(), and assert.

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors