unsigned char pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wallacej

    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(&i mgIPPCannyOut, "byte", dev->nBufferWidth ,
    dev->nBufferHeigh t, (long)myImage);

    Thank You

  • Victor Bazarov

    #2
    Re: unsigned char pointer

    wallacej wrote:[color=blue]
    > 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?[/color]

    No.

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

    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

    Comment

    • Mike Wahler

      #3
      Re: unsigned char pointer


      "wallacej" <jamie_r_wallac e@yahoo.co.uk> wrote in message
      news:1123603039 .226733.240440@ g43g2000cwa.goo glegroups.com.. .[color=blue]
      > Does anybody know why
      >
      > unsigned char myImage[512*480]; works but
      >
      > unsigned char myImage[1004*1001]; does not?[/color]

      Please describe 'work' and 'not work'. How does
      your program's behavior (or success/failure of compile)
      differ when using each of those definitions?
      [color=blue]
      >
      > I think its because the second line is a value too big for unsigned
      > char, is this correct?[/color]

      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. :-)
      [color=blue]
      >
      > If so:
      >
      > How do I create this pointer for the size 1004*1001?[/color]

      What pointer? There is no pointer in your example code.
      Only arrays.
      [color=blue]
      > I have tried
      > using long, int[/color]

      It seems to me you're simply guessing, 'shooting in the dark'.
      I strongly recommend some books and study/practice time.
      [color=blue]
      > etc but the image processing function that I pass the
      > pointer to does not accept this.[/color]

      What function? What are its argument types and return type?
      [color=blue]
      >The function requires me to cast the
      > unsigned char[/color]

      What unsigned char?
      [color=blue]
      >into a long[/color]

      Why? Is one of its paramters type 'long'? If so, why
      are you passing an unsigned char?
      [color=blue]
      > when I pass the pointer,[/color]

      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)).

      [color=blue]
      >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////////[/color]

      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.
      [color=blue]
      >
      >
      > //create a Halcon Image to receive output from edge detection
      > ::gen_image1(&i mgIPPCannyOut, "byte", dev->nBufferWidth ,
      > dev->nBufferHeigh t, (long)myImage);[/color]

      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


      Comment

      • Default User

        #4
        Re: unsigned char pointer

        Mike Wahler wrote:
        [color=blue]
        >
        > "wallacej" <jamie_r_wallac e@yahoo.co.uk> wrote in message
        > news:1123603039 .226733.240440@ g43g2000cwa.goo glegroups.com.. .[/color]
        [color=blue][color=green]
        > > I think its because the second line is a value too big for unsigned
        > > char, is this correct?[/color]
        >
        > No. The range of a type has no bearing at all upon how
        > large an array can be.[/color]


        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

        Comment

        • Mike Wahler

          #5
          Re: unsigned char pointer


          "Default User" <defaultuserbr@ yahoo.com> wrote in message
          news:3lsd0fF145 e5tU4@individua l.net...[color=blue]
          > Mike Wahler wrote:
          >[color=green]
          >>
          >> "wallacej" <jamie_r_wallac e@yahoo.co.uk> wrote in message
          >> news:1123603039 .226733.240440@ g43g2000cwa.goo glegroups.com.. .[/color]
          >[color=green][color=darkred]
          >> > I think its because the second line is a value too big for unsigned
          >> > char, is this correct?[/color]
          >>
          >> No. The range of a type has no bearing at all upon how
          >> large an array can be.[/color]
          >
          >
          > I'm not sure you said what you meant to say there.[/color]

          Perhaps not. Happens to me all the time with women. :-)
          [color=blue]
          > 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.[/color]

          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'.)
          [color=blue]
          >
          > 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.[/color]

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

          -Mike


          Comment

          • wallacej

            #6
            Re: unsigned char pointer

            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

            Comment

            Working...