473,396 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

unsigned char pointer

Does anybody know why

unsigned char myImage[512*480]; works but

unsigned char myImage[1004*1001]; does not?

I think its because the second line is a value too big for unsigned
char, is this correct?

If so:

How do I create this pointer for the size 1004*1001? I have tried
using long, int etc but the image processing function that I pass the
pointer to does not accept this. The function requires me to cast the
unsigned char into a long when I pass the pointer, I don't know if this
is making a difference; as your probably confused heres some code:

unsigned char myImage[512 * 480]; //Size for Halcon image
//unsigned char myImage[1004 * 1001]; //Size for Halcon image ///does
not work////////
//create a Halcon Image to receive output from edge detection
::gen_image1(&imgIPPCannyOut, "byte", dev->nBufferWidth,
dev->nBufferHeight, (long)myImage);

Thank You

Aug 9 '05 #1
5 8917
wallacej wrote:
Does anybody know why

unsigned char myImage[512*480]; works but

unsigned char myImage[1004*1001]; does not?

I think its because the second line is a value too big for unsigned
char, is this correct?


No.

<compilerspeicific>
If this is an automatic array, your _stack_ is probably too small to
accommodate that large of an array.
</compilerspeicific>

Try a dynamic one:

unsigned char *myImage = new unsigned char[1004*1001];

just don't forget to dispose of it when you don't need it any longer:

delete[] myImage;

V
Aug 9 '05 #2

"wallacej" <ja*************@yahoo.co.uk> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Does anybody know why

unsigned char myImage[512*480]; works but

unsigned char myImage[1004*1001]; does not?
Please describe 'work' and 'not work'. How does
your program's behavior (or success/failure of compile)
differ when using each of those definitions?

I think its because the second line is a value too big for unsigned
char, is this correct?
No. The range of a type has no bearing at all upon how
large an array can be. Without more specific description
of 'does not work', I can only make a few guesses:

- Your implementation's type 'size_t' range does not include the
value 1004 * 1001.

- Your arrays above are defined with automatic storage duration
(i.e. at block scope), and 1004 * 1001 is larger than the number
of bytes alloted for automatic objects (can cause many implementations
to issue a 'stack overflow' message.
- Your arrays above are defined with static storage duration
(i.e. at file scope, or at block scope with the 'static' qualifier),
and 1004 * 1001 is larger than the number of bytes alloted for static
storage.

- The moon is in the wrong phase. :-)

If so:

How do I create this pointer for the size 1004*1001?
What pointer? There is no pointer in your example code.
Only arrays.
I have tried
using long, int
It seems to me you're simply guessing, 'shooting in the dark'.
I strongly recommend some books and study/practice time.
etc but the image processing function that I pass the
pointer to does not accept this.
What function? What are its argument types and return type?
The function requires me to cast the
unsigned char
What unsigned char?
into a long
Why? Is one of its paramters type 'long'? If so, why
are you passing an unsigned char?
when I pass the pointer,
What pointer? (Yes, when passed to a function, an array
is converted to a pointer to its first element, but we
cannot know if you're doing things correctly without
some description of the function you're calling (esp.
its signature)).

I don't know if this
is making a difference; as your probably confused heres some code:

unsigned char myImage[512 * 480]; //Size for Halcon image
//unsigned char myImage[1004 * 1001]; //Size for Halcon image ///does
not work////////
Yes, your description does confuse me as to what you're
really asking. And no, that code doesn't help, it's exactly
the same as that near the top of your message. Again, saying
'does not work', helps us help you not at all.


//create a Halcon Image to receive output from edge detection
::gen_image1(&imgIPPCannyOut, "byte", dev->nBufferWidth,
dev->nBufferHeight, (long)myImage);


It's almost certainly a mistake to cast 'myImage' to type long.
What does such a value *mean*?

I suspect you need to do more reading about how to correctly
use the 'gen_image1' function (which part of course isn't topical
here).

-Mike
Aug 9 '05 #3
Mike Wahler wrote:

"wallacej" <ja*************@yahoo.co.uk> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...

I think its because the second line is a value too big for unsigned
char, is this correct?


No. The range of a type has no bearing at all upon how
large an array can be.

I'm not sure you said what you meant to say there. The range of a type
is usually closely tied to the size of the type. The size of the type
can affect how large of an aggregate can be created by the
implementation.

The fact that the index can't be contained in the type is of no
consequence, because the array isn't indexed with the base type of the
array.


Brian
Aug 9 '05 #4

"Default User" <de***********@yahoo.com> wrote in message
news:3l*************@individual.net...
Mike Wahler wrote:

"wallacej" <ja*************@yahoo.co.uk> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
> I think its because the second line is a value too big for unsigned
> char, is this correct?


No. The range of a type has no bearing at all upon how
large an array can be.

I'm not sure you said what you meant to say there.


Perhaps not. Happens to me all the time with women. :-)
The range of a type
is usually closely tied to the size of the type. The size of the type
can affect how large of an aggregate can be created by the
implementation.
Agreed. I suppose I meant to say, rather than (total) 'size
of an array', was 'number of elements in an array' (which is
of course governed by the range of type 'size_t'.)

The fact that the index can't be contained in the type is of no
consequence, because the array isn't indexed with the base type of the
array.


Right. Thanks for trying to help divert any possible misunderstandings
my poor wording may have caused anyone.

-Mike
Aug 9 '05 #5
thanks for your help guys. I have read all of your suggestions and
learnt a great deal, you'll have probably guessed that I'm a bit of an
amateur at C++.

I started working through the list of suggestions in this topic in an
effort to solve my problem and the first suggestion seems to be
working. I created a dynamic array which does the job nicely.
However, my imaging system stops detecting particles after a certain
amount of time/images/particles. I have a feeling I've got a memory
leak somewhere. Anyhow, I'll rig the system up to a controlled test
and if the problem is relevant to this group i'll get back to you guys.

Thanks again

Wallace

Aug 10 '05 #6

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

Similar topics

5
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
1
by: b83503104 | last post by:
When are they not consistent?
1
by: cbachellam | last post by:
Hello, I am trying to call c++ dll function calls from C#. The c++ dll function takes in pointer to unsigned char array. Can anybody help me in what marshalling parameter value that i have to...
2
by: Tom | last post by:
Hi newsgroup, I have read a lot af articles about marshalling in C#, but none of them could help me to solve the following problem: There is a C-DLL with the following header-file: ++++++++...
4
by: cdrom205 | last post by:
static void MDString ( unsigned char *input) { MD5_CTX context; unsigned char digest; unsigned int len = sizeof(input);//strlen (const char*) md5.MD5Init (&context); md5.MD5Update...
5
by: ryanlee101 | last post by:
I am getting a exception error when I complie my code. The error is: - imageData 0x00000000 <Bad Ptr> type unsigned char * I think it is from when I declare some of my char variables
2
yabansu
by: yabansu | last post by:
Hi, I just want to know if there is a way of converting a string variable into a const unsigned char pointer. Alternatively, I expect a blabla() function as the following: string str = "Hello";...
30
by: Yevgen Muntyan | last post by:
Hey, Why is it legal to do union U {unsigned char u; int a;}; union U u; u.a = 1; u.u; I tried to find it in the standard, but I only found that
7
by: edsunder | last post by:
I'm making a "wrapper" for an unmanaged DLL (written, I'm fairly certain in C). I have a c++ "wrapper" that I'm trying to convert to VB.net. I've got most of the program working, but I've hit a brick...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.