Click here to Skip to main content
13,298,965 members (37,011 online)
Click here to Skip to main content
Add your own
alternative version


13 bookmarked
Posted 14 Sep 2005

Anonymous DataChunk in a non-MFC way

, 14 Sep 2005
Rate this:
Please Sign up or sign in to vote.
An anonymous DataChunk class to simplify memory management.


If you have used the std::string and C-style string, you must think the std::string is so convenient in memory management. You can append/delete chars in any way without considering about the memory allocation. But there isn't any class for a byte stream in the std library. So, here's an implementation for a byte stream. I often use it when using Windows APIs, such as those for file operation, network, etc.


Here's the test code, I think it's so simple that a detailed explanation is not needed:

#include <iostream>
using namespace std;

#include "Easiware\DataChunk.h"

void main()
    Easiware::Memory::CDataChunk dc;
    dc    << 100
        << "test"
        << true;

    int i;
    std::string s;
    bool b;

    dc >> i >> s >> b;

    cout << i << endl
         << s << endl
         << b << endl;


I wrote the code just after reading the book << Exceptional C++ >>, so I think this can be called an Exception-Safe class :). Hope you enjoy it, and thanks for any advice. Finally, thanks for reading this article, and sorry for my poor English.


This article, along with any associated source code and files, is licensed under The BSD License


About the Author

Web Developer
China China
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionWhat is the difference to std::stringstream? Pin
cqz6gt795f16-Sep-05 0:49
membercqz6gt795f16-Sep-05 0:49 
AnswerRe: What is the difference to std::stringstream? Pin
balloy17-Sep-05 23:13
memberballoy17-Sep-05 23:13 
GeneralLike it Pin
Jerry Evans15-Sep-05 3:42
memberJerry Evans15-Sep-05 3:42 
GeneralThanks your idea Pin
balloy15-Sep-05 20:59
memberballoy15-Sep-05 20:59 
GeneralRe: Thanks your idea Pin
Johann Gerell18-Sep-05 22:45
memberJohann Gerell18-Sep-05 22:45 
GeneralRe: Thanks your idea Pin
balloy18-Sep-05 23:34
memberballoy18-Sep-05 23:34 
GeneralRe: Thanks your idea Pin
Johann Gerell24-Sep-05 12:22
memberJohann Gerell24-Sep-05 12:22 
GeneralThanks, I found it Pin
balloy25-Sep-05 17:56
memberballoy25-Sep-05 17:56 
Generalmemcpy Pin
Pierre Couderc19-Sep-05 23:41
memberPierre Couderc19-Sep-05 23:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 14 Sep 2005
Article Copyright 2005 by balloy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid