|
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
|
|
|
|
|
For which purpose do you want to truncate it ? Do you want to convert it to a string and display it somewhere ? If that's the case, you can use sprintf and specify the precision:
double x = 345.2214455;<br />
char szBuffer[255];<br />
sprintf(szBuffer,"%.4f",x);
|
|
|
|
|
I want to compare to numbers, for example:
2.0024334 and 2.0024992 should be seen as equal because the first 4 decimals are the same.
And I want to be able to select the number of decimals that are taken into account
|
|
|
|
|
piul wrote: 2.0024334 and 2.0024992 should be seen as equal because the first 4 decimals are the same.
Then the best way is
double x = 2.0024334;
double y = 2.0024992;
const double EPS = .0001;
if ( fabs(x-y) < EPS )
{
}
else
{
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
double x = 345.2214455;
x = floor(x * 10000)/10000;
or
double x = 345.2214455;
x = ((int)( x * 10000)) / 10000.0;
Please note:
(1) Care should be taken with negative values.
(2) The truncation is not exact (due to double numbers nature)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
|
That don't work for you, see http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2452741[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
The easiest way is certainly doing something like
double x = 345.2214455;
long tmp = static_cast<long>(x*10000);
x = tmp/10000.0;
|
|
|
|
|
Hello friends.
The exe of my project works well in Debug mode and has some problem in
Release mode and it shows the messagebox to tell the microsoft about this
problem with send and don't send buttons.
Could you tell me the problems that could be arrived if I want to distribute the debug version of my application what care should be taken?
ritz1234
|
|
|
|
|
ritz1234 wrote: Could you tell me the problems that could be arrived if I want to distribute the debug version of my application what care should be taken?
Legally you can't distribute a debug version of your program. Anyway, if the release version crashes, it means that something is wrong and that your code is not totally stable. You should try to fix that instead.
Here is a great link about surviving the release version.[^]
|
|
|
|
|
Don't distribute the Debug version, fix the Release one, it shouldn't be so difficult.
See [^] and [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
See Here[^]
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
In my project (i am using visual studio 2005 ) i need to simulate the task manager model. i can able to extract all the informations using
CreateToolhelp32Snapshot .But i was unable to identify the username assoicated with the processes .Is any APIs are there for it? or any other way to achieve this ?
vineesh
|
|
|
|
|
May be the following useful,
PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
PSID psidOwner = NULL;
TCHAR lpName[256];
TCHAR lpReferencedDomainName[256];
SID_NAME_USE eUse;
if (ERROR_SUCCESS == GetSecurityInfo(
GetCurrentProcess(),
SE_KERNEL_OBJECT,
OWNER_SECURITY_INFORMATION,
&psidOwner,
NULL,
NULL,
NULL,
&pSecurityDescriptor
))
{
DWORD cchName = 256;
DWORD cchReferencedDomainName = 256;
if (LookupAccountSid(
NULL,
psidOwner,
lpName,
&cchName,
lpReferencedDomainName,
&cchReferencedDomainName,
&eUse
))
{
CString Msg;
Msg.Append(_T("User Name : "));
Msg.Append(lpName);
Msg.Append(_T(" Domain Name : "));
Msg.Append(lpReferencedDomainName);
MessageBox(Msg);
}
LocalFree(pSecurityDescriptor);
}
|
|
|
|