Click here to Skip to main content
Licence 
First Posted 14 Sep 2005
Views 23,409
Bookmarked 12 times

Anonymous DataChunk in a non-MFC way

By | 14 Sep 2005 | Article
An anonymous DataChunk class to simplify memory management.

Introduction

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.

Usage

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;
}

Others

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

balloy

Web Developer

China China

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWhat is the difference to std::stringstream? Pinmembercqz6gt795f23:49 15 Sep '05  
AnswerRe: What is the difference to std::stringstream? Pinmemberballoy22:13 17 Sep '05  
GeneralLike it PinmemberJerry Evans2:42 15 Sep '05  
GeneralThanks your idea Pinmemberballoy19:59 15 Sep '05  
GeneralRe: Thanks your idea PinmemberJohann Gerell21:45 18 Sep '05  
GeneralRe: Thanks your idea Pinmemberballoy22:34 18 Sep '05  
GeneralRe: Thanks your idea PinmemberJohann Gerell11:22 24 Sep '05  
GeneralThanks, I found it Pinmemberballoy16:56 25 Sep '05  
Generalmemcpy PinmemberPierre Couderc22:41 19 Sep '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.5.120517.1 | Last Updated 14 Sep 2005
Article Copyright 2005 by balloy
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid