Introduction to TBuf

Some temporary variables may be used during Ascend C programming. The buffer occupied by these temporary variables can be managed using the TBuf data structure. The storage location is set using template parameters and can be set to different TPosition logical locations.

TBuf is inherited from the TQueBind parent class. The inheritance relationship is as follows:

The storage space occupied by TBuf is managed by TPipe. You can call InitBuffer to initialize the memory for TBuf, and then call Get to obtain a tensor of a specified length for computing.

The differences between using InitBuffer to allocate memory to TBuf and allocating memory to a queue are as follows:

  • The buffer space allocated to TBuf can only be used for calculation and cannot be enqueued or dequeued.
  • If the memory initialization API is called once, TPipe allocates one buffer to TBuf. You can allocate multiple buffers for the queue by setting parameters. To use multiple temporary variables, you need to define multiple TBuf data structures and call the InitBuffer API for each TBuf data structure to initialize the memory.
  • Tensors obtained by TBuf do not need to be released.