How to inspect dynamic array ( my_struct* array) ? 
Author Message
 How to inspect dynamic array ( my_struct* array) ?

Hello,

I've got one problem with the VC de{*filter*} :

my_struct * toto = NULL;
toto = malloc( sizeof(my_struct) *NbElement );

How could I see my stucture array ? I can only see the firt element of
'toto' or I must type toto[1],toto[2]...witch is very laborious.
Is there an best solution ?

Bertrand



Fri, 01 Dec 2000 03:00:00 GMT  
 How to inspect dynamic array ( my_struct* array) ?

Hi, Bertrand.

To display a dynamicly allocated array you can bring up a memory window,
then drag the address of the array diplayed in your watch window to the
point in the memory window you'd like it to appear.  Then you can
right-click the memory window and select from very few options of display
(8, 16 or 32 bit elemants).  That's about as helpful as the VC de{*filter*}
gets.  This method is ok for arrays, where all the elements are the same
size, but for structures, you'd have to figure out where the  members are
based on their type.  As far as I know, there is no other way to display
things that are pointed to by pointers.  Also, if you want to look at more
than one array (forget structures) at a time, you are SOL, because VC cann't
display more than one memory window.  VC is IMHO one of the most useless
de{*filter*}s I've seen.  I've used many de{*filter*}s including some very dinky
ones for the embeded DSPs and even those can do basic things like display
contents of memory in a friendly manner.

If anyone out there knows of a better way to display structures/arrays
pointed to by pointers, please let me know, I am really jumping through
hoops to do one of the most basic de{*filter*} jobs: inspect variables in
memory.

Quote:

>Hello,

>I've got one problem with the VC de{*filter*} :

>my_struct * toto = NULL;
>toto = malloc( sizeof(my_struct) *NbElement );

>How could I see my stucture array ? I can only see the firt element of
>'toto' or I must type toto[1],toto[2]...witch is very laborious.
>Is there an best solution ?

>Bertrand



Tue, 05 Dec 2000 03:00:00 GMT  
 How to inspect dynamic array ( my_struct* array) ?

Quote:

> To display a dynamicly allocated array you can bring up a memory window,
> then drag the address of the array diplayed in your watch window to the
> point in the memory window you'd like it to appear.  Then you can
> right-click the memory window and select from very few options of display
> (8, 16 or 32 bit elemants).  That's about as helpful as the VC de{*filter*}
> gets.  

There are actually 16 different formats.  They are listed in
Tools.Options.Debug

The de{*filter*} already does a great job with both ANSI and UNICODE
strings, since it can figure out where they end.  You'll need to turn
on Unicode Strings in the above options.

Quote:
> If anyone out there knows of a better way to display structures/arrays
> pointed to by pointers, please let me know, I am really jumping through
> hoops to do one of the most basic de{*filter*} jobs: inspect variables in
> memory.

There are a few hacks that might do the trick, but they're not
great.

The first is to keep a static array around just in case:

        #ifdef DEBUG
        // To view an array sometimes
        static my_struct temp[100];
        #endif

And create a function to copy into it:

        void viewTemp (my_struct *p, int n)
        {
                memcpy (temp, p, sizeof (my_struct) * n);
        }

Then put "viewTemp (toto, NbElement)" and "temp" in the watch window.
Updated every step!

The second is to use an easy-to-edit index.  Put "toto[i]" and "i" in
the watch window.  Use TAB-TAB-j-ENTER where 0<=j<n to go through the
elements.

The third is a *real* hack.  Put "toto[i]", "i=-1", and "toto[i+1]" in
the watch window.  Change the middle one to "i++".  Use Alt-Num* to
force a re-evalution of the watches, thereby cycling through the
elements.
--



Sun, 10 Dec 2000 03:00:00 GMT  
 How to inspect dynamic array ( my_struct* array) ?

Thanks, Jay.

That helps a little with arrays, what about structures, where elements are
of different types?  Also what if you want to see two non-contiguous chunks
of memory at the same time?  I know, I know, one can always come up with
hacks, but we are talking about state of the art development tool, here.  I
mostly work with embeded systems and the tools there are at least good at
examining memory in different ways without doing tricks.

Quote:

>There are a few hacks that might do the trick, but they're not
>great.

>The first is to keep a static array around just in case:

--snip
Quote:

>The second is to use an easy-to-edit index.  Put "toto[i]" and "i" in
>the watch window.  Use TAB-TAB-j-ENTER where 0<=j<n to go through the
>elements.

>The third is a *real* hack.  Put "toto[i]", "i=-1", and "toto[i+1]" in
>the watch window.  Change the middle one to "i++".  Use Alt-Num* to
>force a re-evalution of the watches, thereby cycling through the
>elements.



Sun, 10 Dec 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Control Arrays/Dynamic Arrays

2. Lists VS. Dynamic Arrays VS. Re-defining Arrays

3. Dynamic arrays not really dynamic in managec C++?

4. char array (array of array...) question

5. HELP -> dynamic array of char** in dynamic array of mystruct**

6. C# Dynamic Array?

7. Error/Bug in VC++ .Net, size of a Dynamic Array

8. Dynamic typed array?

9. Dynamic Alloc - Arrays

10. Dynamic arrays.

11. Multi-dimensional array using dynamic memory allocation

12. Can't free dynamic array (Visual C++ 6.0)

 

 
Powered by phpBB® Forum Software