SHARE
Facebook X Pinterest WhatsApp

Expandable, Data Type-Neutral Buffer Class

CBuffer is an expandable buffer class which can expand when needed and allows insertion of data and many operation on buffer Using the CBuffer Class In order to use the class, simply do the following. (Remember that if any of this is unclear, I have included a demo application that will hopefully clear up any […]

Written By
thumbnail
CodeGuru Staff
CodeGuru Staff
Feb 11, 2000
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

CBuffer is an expandable buffer class which can expand when needed and
allows insertion of data and many operation on buffer

Using the CBuffer Class


In order to use the class, simply do the following. (Remember that if any of this is


unclear, I have included a demo application that will hopefully clear up any


misunderstandings.


  1. Instantiate the CBuffer object
  2. Call the CBuffer Init method
  3. CBuffer:Init(int nSizeOfBuffer, int nNbrOfElements,
      int nIncrementalGrowthValue)

  4. Insert data into the buffer by using any of the following mechanisms:

  5. int CBuffer::PutData(BYTE *pBuff)


  6. void CBuffer::operator+=(BYTE *pBuff)


  7. int CBuffer::InserData(BYTE * pBuff,int nOffset)


  8. Retrieve data from the buffer by calling any of the following methods:

  9. int CBuffer::GetData(BYTE * pBuff,int nIndex)


  10. BYTE *CBuffer::GetPointer(int nIndex) const


  11. Use any of the following helper methods

  12. m_Buffer.GetSize();


  13. m_Buffer.GetTotalElements();


  14. m_Buffer.GetStructureSize();


  15. m_Buffer.GetFreeSp();


  16. m_Buffer.GetFreeStSp();



Header File (lists available CBuffer methods)


#pragma once
class CBuffer
{
public:
 CBuffer();
 virtual ~CBuffer();
 int Init(int,int,int);
 int PutData(BYTE*);
 void operator+=(BYTE *);
 int InserData(BYTE*,int);
 int GetData(BYTE*,int);
 int ExpandBuff(int);
 int GetSize();
 int GetTotalElements();
 int GetStructureSize();
 int GetFreeSp();
 int GetFreeStSp();
 BYTE *GetPointer(int nIndex)const;
 BYTE *CBuffer::operator[](int nIndex)const;
 private:
 BYTE *m_pBuff;
 int m_nStructSize;
 int m_nTotal;
 int m_nOffset;
 int m_nSize;
 int m_nStructOffset;
 int m_nIncerment;
};

Downloads

Download demo project – 14 Kb

Recommended for you...

Video Game Careers Overview
CodeGuru Staff
Sep 18, 2022
Dealing with non-CLS Exceptions in .NET
Hannes DuPreez
Aug 5, 2022
Online Courses to Learn Video Game Development
Ronnie Payne
Jul 8, 2022
Best Online Courses to Learn C++
CodeGuru Staff
Jun 25, 2022
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.