|
a pointer is only an address in memory.
if you handle an array, you actually use a pointer to the 1st element.
the VC6 debugger is not very powerful (actually, VC6 itself is far outdated by its new versions).
so if you want to see the other elements, you have to specify yourself the address of the element you need to watch AFAIK...
|
|
|
|
|
toxcct wrote: the VC6 debugger is not very powerful (actually, VC6 itself is far outdated by its new versions).
so if you want to see the other elements, you have to specify yourself the address of the element you need to watch AFAIK...
you are correct, But viewing the List items is very simple from VC6.0, we don't want to explicitly specify the address of the next element, it shows tree view in the watch window and expands the list if the first element is in the watch window.
struct ListNode
{
int iData;
struct ListNode *pNext;
};
int main(int argc, char* argv[])
{
struct ListNode Head, Middle, Tail;
Head.pNext = &Middle;
Middle.pNext = &Tail;
Tail.pNext = 0;
return 0;
}
I can view the list items in the above program as tree view in the watch window of VC6.0, even VC6.0 supports drag and drop variable to watch window.
|
|
|
|
|
I know what is a linked list, but I don't think the OP is using them at all.
hence my reply, refering to arrays and pointer arithmetic. I think he used the term "list" when he wanted to say "array"...
|
|
|
|
|
toxcct wrote: I think he used the term "list" when he wanted to say "array"...
struct ListNode list[3];
struct ListNode *plist = list;
still i can view as tree control of array element with tree labels like [0], [1], [2] .. in VC6.0 watch window
when watching variable as "list" and "plist,3"
|
|
|
|
|
I think in VC6, you can type something like: 'list,m' in the watch window
This will show you the entire memory. VS2003, 2005, 2008 supports this.
God bless,
Ernest Laurentin
|
|
|
|
|
thanks , you answer is right.
|
|
|
|
|
I have a CListBox in which I display a string using the AddString function
For the CString I use it's Format Function
CListBox List1;
CString str;
short Data[50];
int DataSize ; /* variable */
DataSize = /*some processing */
for ( i=0;i<j;i++)
{
/* some other processing*/
str.Format("%X ",Data[i]);
List1.AddString(str);
}
My current code Data is outputed in this manner
05
25
6F
E2
I want my display to be like this :
Contents of Data[DataSize-1] Contents of Data[DataSize-2] .... Data[0]
e.g if Data[0]= 05 Data[1]= 25 Data[2]=6F and Data[3]= E2
Display I want is
E2 6F 25 05 (ie in the same line )
How do I go about doing it ? any help woould be appreciated
|
|
|
|
|
Use AppendFormat() in place of Format(). And Addstring to the list when you complete the line.
And Are you expecting data in separate column?
|
|
|
|
|
Is AppendFormat present CString Function in VC++ 6.0 ?
|
|
|
|
|
Are you expecting data in separate column?
|
|
|
|
|
I want data to displayed like this
25 4E 20 F6 .... (for example)
and not like this
25
4E
20
F6 ( I dont want for it to displayed in Different rows but all in the same row)
|
|
|
|
|
Then I am not sure AppendFormat is supported in VS 6.0. But i think it should have concatenation operator. Format using temp variable and concatenate to main string.
If want in separate column go for ListView control, CListCtrl.
|
|
|
|
|
You can concatenate all hex. digits in one string. As shown below:
CString strLine;
for ( i=0;i<j;i++)>
{
/* some other processing*/
str.Format("%X ",Data[i]);
strLine += str;
}
List1.AddString(strLine);
In this approach, you can also use tab ('\t') separator char. between numbers, then you can use CListBox::SetTabStops() function in order to display it properly.
If you want to have real tabular view, you can employ CListCtrl (list view control) instead of CListBox.
|
|
|
|
|
thanks that does it
I am new to C++
|
|
|
|
|
it's because you're using a List control, and you're setting each string on a line.
you have to build the single string, and do the List1.AddString() after the for() loop...
|
|
|
|
|
toxcct wrote: it's because you're using a List control...
How did you infer this?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: How did you infer this?
List1.AddString() is explicit enough...
|
|
|
|
|
Isn't Addstring() for listboxes?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Isn't Addstring() for listboxes?
and what did I say ?
i said *a* List *Control*, not meaning CListCtrl in particular, but a control which managed datas as a list...
|
|
|
|
|
Hello everyone,
Quoted from GotW #54 about redundant allocation in vector and deque. What makes me confused is "because none of the allocations are redundant". I think it means,
The context is about adding new elements at the end, not about insert elements at any arbitrary location (e.g. in the middle), right?
1. For deque, when allocating memory for new elements at the end, no need to reallocate, i.e. allocate new space, copy old elements to new space and free old memory -- so no redundant allocation for existing component again;
2. For vector, when allocating memory for new elements at the end, when capacity == current size, need to reallocate, i.e. allocate new space, copy old elements to new space and free old memory -- so redundant allocation for existing components again.
My understanding correct?
http://www.gotw.ca/gotw/054.htm
--------------------
3. A deque is easier to use, and inherently more efficient for growth, than a vector. The only operations supplied by vector that deque doesn't have are capacity() and reserve() -- and that's because deque doesn't need them! For vector, calling reserve() before a large number of push_back()s can eliminate reallocating ever-larger versions of the same buffer every time it finds out that the current one isn't big enough after all. A deque has no such problem, and having a deque::reserve() before a large number of push_back()s would not eliminate any allocations (or any other work) because none of the allocations are redundant; the deque has to allocate the same number of extra pages whether it does it all at once or as elements are actually appended.
--------------------
thanks in advance,
George
|
|
|
|
|
the problem is how deque and vector manage their own internal buffers.
the way vector allocates its memory is like this: if you create an empty vector, it automatically reserves the amount of memory for 10 elements (if I remember well). vector has another constructor to tell it another starting reserved memory.
if you never use reserve(), vector will manage its internal buffer alone, and you have to know that its size doesn't increase constantly.
for example (and that's just an example - it may differ from implementations):
class T {};
std::vector<T> v = vector<T>();
v.pushback(T());
v.pushback(T());
v.pushback(T());
v.pushback(T());
v.pushback(T());
v.pushback(T());
v.pushback(T());
v.pushback(T());
v.pushback(T());
v.pushback(T());
as you see, vector has a buffer which doesn't always grow when inserting a new element.
the advantage of this is that it ensures that all the elements in the vector are adjacent.
the inconvenient is that when you insert or delete elements in the middle of the container, it has to move every other elements after the position you insert/delete, thus reallocation.
deque work in a totally different way.
all elements are not adjacent in memory. deque is a linked list, that means each element is somewhere in memory, and has a pointer to the next (and previous) element. so, when you insert an element in a deque, you just have to new it, and change the pointers to incorporate the new element.
same with deletion. you just have to change the pointers of the previous (and next) elements to point now on each others, jumping the element we're deleting...
so, with a deque, the length() is always the allocated amount of memory, that why the writer said that "none of the allocations are redundant"...
modified on Thursday, March 6, 2008 3:16 AM
|
|
|
|
|
Hi toxcct,
I agree and understand your analysis. For the below comments from you,
toxcct wrote: when you insert of delete elements in the middle of the container
It should be "when you insert or delete elements in the middle of the container"? A typo?
regards,
George
|
|
|
|
|
George_George wrote: It should be "when you insert or delete elements in the middle of the container"? A typo?
yes
|
|
|
|
|
Thanks toxcct,
Question answered.
regards,
George
|
|
|
|
|
There goes an easy one:
How do I truncate a double number (I've been looking about but haven't find a way) but leaving some decimal digits. For example:
double x = 345.2214455; to x = 345.2214;
Thanks a lot
|
|
|
|