Re: buffer...
From: Jase (jshelley_at_nospam.optushome.com.au)
Date: 04/08/04
- Next message: Mike Maffa: "Re: CTypedPtrMap, CompareElements or overload == operator"
- Previous message: Scott McPhillips [MVP]: "Re: C++ Standard Library"
- In reply to: RBert: "Re: buffer..."
- Next in thread: Joseph M. Newcomer: "Re: buffer..."
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 9 Apr 2004 08:58:38 +1000
Okely dokely then. In the case of that function, the buffer can be anything
at all. That's why it's declared as a "const void *". The first parameter is
a pointer to something you want to write to a file, the second parameter is
the number of bytes to write. Here's a couple of examples:
The CFile object used in these examples is the variable "f".
Note that the name of an array variable with no [] is a pointer to the first
element.
1. A line of text.
char szLine[] = "This is a line of text\r\n";
f.Write(szLine, strlen(szLine));
1a. Same thing using a CString
CString str = "This is a lineof text\r\n";
f.Write((LPCTSTR)str, str.GetLength());
str.ReleaseBuffer();
2. An integer array
int array[] = {5, 10, 13};
f.Write(array, sizeof(array));
3. A class object
CSize sz(23, 50);
f.Write(&sz, sizeof(sz)); // note we had to use the & operator here, as
sz is a single object, not an array.
4. A raw integer
int val = 2345;
f.Write(&val, sizeof(val)); // or sizeof(int)
It's all about the fact that an object is ultimately just a map that gives
meaning to the bytes stored in a particular memory block. By taking a
pointer to the first byte of that block and the length of the block as
parameters, this function treats all objects the same. It doesn't know or
care what the memory represents. I recommend you take the time to consider
this, as a good understanding of pointers, objects, and the memory that they
use is essential to C++ programming.
Jase
"RBert" <drbert@microcore.net> wrote in message
news:urH7HhOHEHA.128@tk2msftngp13.phx.gbl...
> Here is a function where I saw mention of a "buffer".
>
>
> CFile::Write
> virtual void Write( const void* lpBuf, UINT nCount );
> throw( CFileException );
>
> Parameters
>
> lpBuf
>
> A pointer to the user-supplied buffer that contains the data to be written
> to the file.
>
>
>
> Thanks,
>
> RABMissouri
>
>
>
>
>
>
>
> "Jase" <jshelley@nospam.optushome.com.au> wrote in message
> news:4072a53a$0$6018$afc38c87@news.optusnet.com.au...
> > In general, a buffer is a block of memory. A function asking for a
buffer
> is
> > asking you do assign the required memory, and pass it a pointer. What
the
> > data in that block means is entirely up to that function.
> >
> > Give me a function, and I can be more specific.
> >
> > Jase
> >
> > "RBert" <drbert@microcore.net> wrote in message
> > news:uAnSsE9GEHA.2160@TK2MSFTNGP12.phx.gbl...
> > > I see that a lot of MFC class methods require buffer parameters. What
> > > exactly, is a buffer?
> > >
> > > Thanks,
> > > RABMissouri
> > >
> >
> >
> >
>
>
- Next message: Mike Maffa: "Re: CTypedPtrMap, CompareElements or overload == operator"
- Previous message: Scott McPhillips [MVP]: "Re: C++ Standard Library"
- In reply to: RBert: "Re: buffer..."
- Next in thread: Joseph M. Newcomer: "Re: buffer..."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|