Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How does CArray work?

How does CArray work?

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresperformancetutorialquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    acerunner316
    wrote on last edited by
    #1

    My app is crashing unexpectedly and I suspect that it is because of the CArray object I am using. I have a CArray inside a structure, and I have an array of this structure. For example:

    struct type1
    {
    unsigned char variable1;
    unsigned char variable2;
    CArray DataPtTable;
    unsigned char variable3;
    };
    type1 myArray[5];

    Now if I call myArray[2].DataPtTable.Add() or SetSize(), how is the memory allocated? I know it does get reallocated, but does that make calls to members of myArray[2].DataPtTable invalid since it is now pointing somewhere else? Or will it begin to overwrite into memory allocated for variable3, etc? Thanks.

    N M N 3 Replies Last reply
    0
    • A acerunner316

      My app is crashing unexpectedly and I suspect that it is because of the CArray object I am using. I have a CArray inside a structure, and I have an array of this structure. For example:

      struct type1
      {
      unsigned char variable1;
      unsigned char variable2;
      CArray DataPtTable;
      unsigned char variable3;
      };
      type1 myArray[5];

      Now if I call myArray[2].DataPtTable.Add() or SetSize(), how is the memory allocated? I know it does get reallocated, but does that make calls to members of myArray[2].DataPtTable invalid since it is now pointing somewhere else? Or will it begin to overwrite into memory allocated for variable3, etc? Thanks.

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      Are performing some operations like type1 stMystruct1; **type1 stMystruct2 = stMystruct1;** ?

      nave [OpenedFileFinder]

      1 Reply Last reply
      0
      • A acerunner316

        My app is crashing unexpectedly and I suspect that it is because of the CArray object I am using. I have a CArray inside a structure, and I have an array of this structure. For example:

        struct type1
        {
        unsigned char variable1;
        unsigned char variable2;
        CArray DataPtTable;
        unsigned char variable3;
        };
        type1 myArray[5];

        Now if I call myArray[2].DataPtTable.Add() or SetSize(), how is the memory allocated? I know it does get reallocated, but does that make calls to members of myArray[2].DataPtTable invalid since it is now pointing somewhere else? Or will it begin to overwrite into memory allocated for variable3, etc? Thanks.

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        The array object remains valid.  The memory allocations and reallocations are internal to the CArray class.  That's the whole idea - so you don't have to worry about it. :) Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        A 1 Reply Last reply
        0
        • M Mark Salsbery

          The array object remains valid.  The memory allocations and reallocations are internal to the CArray class.  That's the whole idea - so you don't have to worry about it. :) Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          A Offline
          A Offline
          acerunner316
          wrote on last edited by
          #4

          So the way I am using CArray is correct? Then the app crashing must be something else. Dam, back to square one. :sigh:

          M 1 Reply Last reply
          0
          • A acerunner316

            So the way I am using CArray is correct? Then the app crashing must be something else. Dam, back to square one. :sigh:

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            acerunner316 wrote:

            So the way I am using CArray is correct?

            From what you've posted, yes. I can't see the stuff in angle brackets though...

            struct type1
            {
            unsigned char variable1;
            unsigned char variable2;
            CArray<???> DataPtTable;
            unsigned char variable3;
            };
            type1 myArray[5];

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            A 1 Reply Last reply
            0
            • M Mark Salsbery

              acerunner316 wrote:

              So the way I am using CArray is correct?

              From what you've posted, yes. I can't see the stuff in angle brackets though...

              struct type1
              {
              unsigned char variable1;
              unsigned char variable2;
              CArray<???> DataPtTable;
              unsigned char variable3;
              };
              type1 myArray[5];

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              A Offline
              A Offline
              acerunner316
              wrote on last edited by
              #6

              I have two CArray objects. One is <WORD, WORD> Other is <float, float> I know there isn't a problem with that part of the declaration.

              M 1 Reply Last reply
              0
              • A acerunner316

                I have two CArray objects. One is <WORD, WORD> Other is <float, float> I know there isn't a problem with that part of the declaration.

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                In that case, looks like there's a problem elsewhere. Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                1 Reply Last reply
                0
                • A acerunner316

                  My app is crashing unexpectedly and I suspect that it is because of the CArray object I am using. I have a CArray inside a structure, and I have an array of this structure. For example:

                  struct type1
                  {
                  unsigned char variable1;
                  unsigned char variable2;
                  CArray DataPtTable;
                  unsigned char variable3;
                  };
                  type1 myArray[5];

                  Now if I call myArray[2].DataPtTable.Add() or SetSize(), how is the memory allocated? I know it does get reallocated, but does that make calls to members of myArray[2].DataPtTable invalid since it is now pointing somewhere else? Or will it begin to overwrite into memory allocated for variable3, etc? Thanks.

                  N Offline
                  N Offline
                  Nelek
                  wrote on last edited by
                  #8

                  Where does the programm crash? Use the debugger and write us some previous lines with the point of your failure.

                  Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you ;)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups