473,804 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BYTE array size

I have a BYTE array -
BYTE const* pbBinary

I would like to know how many bytes in that byte array

but if I do - sizeof(* pbBinary); - then I got 1
but if I do - sizeof( pbBinary); - then I got 4

I am sure the array has hundreds of bytes

how can I do that?

=============== =======

BYTE const* pbBinary = &bytes[0];
int size = sizeof( pbBinary);
Nov 20 '08 #1
10 24830
"Chunekit Pong" <wo********@yah oo.comwrote in message news:f5******** *************** *********@4ax.c om...
>I have a BYTE array -
BYTE const* pbBinary
You don't have a BYTE array, you have a pointer to BYTE.
(What is a BYTE?)

I would like to know how many bytes in that byte array

but if I do - sizeof(* pbBinary); - then I got 1
but if I do - sizeof( pbBinary); - then I got 4

I am sure the array has hundreds of bytes

how can I do that?
Without other information you can't.
Nov 20 '08 #2
On Nov 20, 8:27*am, Chunekit Pong <worlman...@yah oo.comwrote:
I have a BYTE array *-
BYTE const* pbBinary

I would like to know how many bytes in that byte array

but if I do - *sizeof(* pbBinary); *- then I got 1
but if I do - sizeof( pbBinary); - then I got 4

I am sure the array has hundreds of bytes
pbBinary is just a pointer.. it does not store the information about
number of bytes/elements it points to
if you care about the size of an "array", use std::vector<ins tead.
m.
Nov 20 '08 #3
On Thu, 20 Nov 2008 08:46:12 +0100, "Fred Zwarts" <F.******@KVI.n l>
wrote:
>"Chunekit Pong" <wo********@yah oo.comwrote in message news:f5******** *************** *********@4ax.c om...
>>I have a BYTE array -
BYTE const* pbBinary

You don't have a BYTE array, you have a pointer to BYTE.
(What is a BYTE?)
>>
I would like to know how many bytes in that byte array

but if I do - sizeof(* pbBinary); - then I got 1
but if I do - sizeof( pbBinary); - then I got 4

I am sure the array has hundreds of bytes

how can I do that?

Without other information you can't.
The whole code is like this - the purpose is to convert binary file
into a Base64 string
=============== ==
typedef unsigned char BYTE;
std::ifstream file1("c:/test2.png");

// read from test2.png into BYTE array
std::vector<BYT Ebytes(
(std::istreambu f_iterator<char >(file1))
, (std::istreambu f_iterator<char >())
);
if(bytes.empty( ))
; // no bytes have been read

BYTE const* pbBinary = &bytes[0];
int size = sizeof(pbBinary );

unsigned long ulEncLen = 0;
char *pEncOut = NULL;

BOOL fRet = ::CryptBinaryTo String( pbBinary, size,
CRYPT_STRING_BA SE64, pEncOut, &ulEncLen );
=============== =====
BOOL WINAPI CryptBinaryToSt ring(
__in const BYTE *pbBinary,
__in DWORD cbBinary,
__in DWORD dwFlags,
__out_opt LPTSTR pszString,
__inout DWORD *pcchString
);
Nov 20 '08 #4
"Chunekit Pong" <wo********@yah oo.comwrote in message news:ok******** *************** *********@4ax.c om...
On Thu, 20 Nov 2008 08:46:12 +0100, "Fred Zwarts" <F.******@KVI.n l>
wrote:
>>"Chunekit Pong" <wo********@yah oo.comwrote in message news:f5******** *************** *********@4ax.c om...
>>>I have a BYTE array -
BYTE const* pbBinary

You don't have a BYTE array, you have a pointer to BYTE.
(What is a BYTE?)
>>
I would like to know how many bytes in that byte array

but if I do - sizeof(* pbBinary); - then I got 1
but if I do - sizeof( pbBinary); - then I got 4

I am sure the array has hundreds of bytes

how can I do that?

Without other information you can't.
The whole code is like this - the purpose is to convert binary file
into a Base64 string
=============== ==
typedef unsigned char BYTE;
std::ifstream file1("c:/test2.png");

// read from test2.png into BYTE array
std::vector<BYT Ebytes(
(std::istreambu f_iterator<char >(file1))
, (std::istreambu f_iterator<char >())
);
if(bytes.empty( ))
; // no bytes have been read

BYTE const* pbBinary = &bytes[0];
int size = sizeof(pbBinary );
bytes.size () gives you the size of the vector.
Nov 20 '08 #5
On Nov 20, 9:25*am, Chunekit Pong <worlman...@yah oo.comwrote:
The whole code is like this - the purpose is to convert binary file
You cannot get the size of an array, by doing sizeof on a pointer to
an external array. Only if the pointer is in fact declared as a
statically dimensioned array (eg. BYTE pbBinary[10]) you can get the
size of the array by doing sizeof(pbBinary ). In your case you are in
the same scope, but still pbBinary is considered as a pointer to a
dynamically allocated or external array. Note that sizeof is
calculated compile time, and when you declare a pointer to an array,
the compiler CANNOT know what the size of the array will be to what
the pointer will point at runtime.
Nov 20 '08 #6
Chunekit Pong wrote:
I have a BYTE array -
BYTE const* pbBinary

I would like to know how many bytes in that byte array

but if I do - sizeof(* pbBinary); - then I got 1
Well, *pbBinary is a BYTE, so you get the size of a BYTE.
but if I do - sizeof( pbBinary); - then I got 4
pbBinary is a pointer to const BYTE, so you get the size of a pointer to
const BYTE.
I am sure the array has hundreds of bytes

how can I do that?
You can't, unless the array contains some end marker that you can use to find
out.

Nov 20 '08 #7
On Nov 20, 12:47 pm, Tonni Tielens <tonnitiel...@g mail.comwrote:
On Nov 20, 9:25 am, Chunekit Pong <worlman...@yah oo.comwrote:
The whole code is like this - the purpose is to convert
binary file
You cannot get the size of an array, by doing sizeof on a
pointer to an external array.
I know what you mean, but you really should say that you can't
get the size of an array given a pointer to its first element.
(Pointers to arrays, i.e. BYTE (*p)[ 200 ], exist, and in such
cases, sizeof( *p ) would be useful. But they aren't very
idiomatic.)
Only if the pointer is in fact declared as a statically
dimensioned array (eg. BYTE pbBinary[10]) you can get the size
of the array by doing sizeof(pbBinary ).
If something is declared as an array, it's not a pointer.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 20 '08 #8
On Nov 20, 8:27 am, Chunekit Pong <worlman...@yah oo.comwrote:
I have a BYTE array -
BYTE const* pbBinary
I would like to know how many bytes in that byte array
but if I do - sizeof(* pbBinary); - then I got 1
but if I do - sizeof( pbBinary); - then I got 4
I am sure the array has hundreds of bytes
Ask whoever created the array to tell you. Once the array has
been converted to a pointer to the first element, all
information concerning the size has been lost.

A better solution might be to use std::vector.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 20 '08 #9
zr
On Nov 20, 10:25*am, Chunekit Pong <worlman...@yah oo.comwrote:
On Thu, 20 Nov 2008 08:46:12 +0100, "Fred Zwarts" <F.Zwa...@KVI.n l>
wrote:
"Chunekit Pong" <worlman...@yah oo.comwrote in messagenews:f5* *************** *************** *@4ax.com...
>I have a BYTE array *-
BYTE const* pbBinary
You don't have a BYTE array, you have a pointer to BYTE.
(What is a BYTE?)
I would like to know how many bytes in that byte array
but if I do - *sizeof(* pbBinary); *- then I got 1
but if I do - sizeof( pbBinary); - then I got 4
I am sure the array has hundreds of bytes
how can I do that?
Without other information you can't.

The whole code is like this - the purpose is to convert binary file
into a Base64 string
=============== ==
* * * * * * * * typedef unsigned char BYTE;
* * * * * * * * std::ifstream file1("c:/test2.png");

* * * * * * * * // read from test2.png into BYTE array
* * * * * * * * std::vector<BYT Ebytes(
* * * * * * * * * * * * (std::istreambu f_iterator<char >(file1))
* * * * * * * * * * * * , (std::istreambu f_iterator<char >())
* * * * * * * * * * * * );
* * * * * * * * if(bytes.empty( ))
* * * * * * * * * * * * ; // no bytes have been read

* * * * * * * * BYTE const* pbBinary = &bytes[0];
* * * * * * * * int size = sizeof(pbBinary );

* * * * * * * * unsigned long ulEncLen = 0;
* * * * * * * * char *pEncOut = NULL;

* * * * * * * * BOOL fRet = ::CryptBinaryTo String( pbBinary, size,
CRYPT_STRING_BA SE64, pEncOut, &ulEncLen );
=============== =====
BOOL WINAPI CryptBinaryToSt ring(
* __in * * * const BYTE *pbBinary,
* __in * * * DWORD cbBinary,
* __in * * * DWORD dwFlags,
* __out_opt *LPTSTR pszString,
* __inout * *DWORD *pcchString
);
The previous posters have explained the problem. A possible fix to
your program:

Instead of:
int size = sizeof(pbBinary );
Try:
int size = bytes.size();
Nov 20 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
24153
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I've noticed a few threads (full of sound and fury, signifying nothing) here recently about allocation of large memory blocks. I'm about to start on a personal pet project where I'll be using memchr(), memcmp(), memmove() a lot. Is there an ANSI C maximium size for character arrays which are guaranteed to succeed, assuming the machine has sufficient memory? And will the memxxx() functions work with that size? I'm looking at hopefully...
3
11472
by: simonc | last post by:
Can you define a property as type Byte array of a specific length? I am trying to pass a byte array which is 3200 bytes in length from one form (in which the bytes are read from a file) to another form (where the content can be edited). I have defined a property for the editing form using the following Dim m_edicin(3199) As Byte Public Property ebcdicin() As Byte Get
5
2589
by: news.microsoft.com | last post by:
Hello, what is the most performant size for the byte array for reading/writing using 2 filestreams? example code: Dim bytearrayinput(4095) As Byte Dim rdlen As Long = 0 Dim totlen As Long = fsInput.Length
8
11662
by: piggy | last post by:
I am trying to convert an image to an byte array (tobytes() method) and from byte array back to an image (frombytes() method). The problem i have here is say the image size is 285 bytes but the total bytes is 635. I know it would include the header but the header should be the same size regardless of the image size. I tested the other image size of 407 bytes and the total bytes array is 727. I am not sure what is wrong? your help would...
23
16448
by: Gerrit | last post by:
Hi all, I'm getting an OutOfMemoryException when I initialize a byte array in C# like this: Byte test = new Byte; I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing wrong?
1
9316
by: | last post by:
Hi all, I am writing a sendmail milter application in Java. The incoming mails will usually have image file as attachments. My application is currently able to extract the ImageFile and save it on the filesystem. This part is working perfectly. ((MimeBodyPart)p).saveFile(new File(p.getFileName())); However, I would like to pass this file as a byte array to a c++ library
10
6388
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it and then convert that to a byte array, pass it to the device, then get a reply and then convert that to a structure. I'm having issues with making sure what I've coded is correct. Cant figure out how to define an array in structure that is a...
3
3614
by: =?Utf-8?B?SXpvcmljaA==?= | last post by:
I observed that WCF client running inside Full Trust mode XBAP application can't read byte array over 16384. If return result is bigger than that size, then client simply get null or Nothing in VB and there are no exceptions. I have tried increasing limits on both client and server. Here is a typical entry: <binding name="myBasicHttpBinding" maxBufferSize="2097152" maxBufferPoolSize="8388608" maxReceivedMessageSize="2097152"...
2
4680
Airslash
by: Airslash | last post by:
Hello, I'm currently working with byte arrays to hold data transmitted over the network, and i'm looking for a way to copy a section of that byte array and return it from a function result. I know I can create a temporary array and call the CopyTo function to copy the data in that array, but I was wondering this this piece of code below with LinQ would do the same. return (from m in Enumerable.Range(0, Size) select RawContent);
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.