|
Hi, everyone!
A book said,
--------
a deque supports the constant time execution of these operations
at the end as well as at the beginning.
Insert and erase in the middle take constant time.
--------
I think the insert and rease in the middle algorithm of
STL deque does not take constant time. The time it
taken can be descripted as O(n). (Since deque is stored as a
linked list and not an array.)
I think only an algorithm takes O(1) time should be treated as
"constant time" algorithm.
Am I correct?
Thanks in advance,
George
|
|
|
|
|
I think that is an error in the book. deque is linear insert/remove in the middle according to my stuff.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks, Tim buddie!
George
|
|
|
|
|
Hey all,
Some doubts:
1- How to make a property of an Activex Control(VC++), shows up at the "properties window" in Visual Basic.
2- How to set up the design-time image resource that will be drawn that represents the Control on the form, when the user drag it from the toolbox to the form. I know it's inside the OnDraw() event, isn't it?
Remebering...all without MFC, just ATL.
Raphael Amorim Dantas Leite
VC++, VB, Java, .NET and eMbedded Programmer
|
|
|
|
|
Hi,
1. Look for BEGIN_PROP_MAP documentation. Sample of usage is then:
BEGIN_PROP_MAP(CMyClass)<br />
...<br />
PROP_ENTRY("PropertyName",23, CLSID_NULL)<br />
END_PROP_MAP()
where 23 is a number equal to DispID of your property (simple the id(23) in your IDL in the property definition)
2. For deciding if you are in design mode or runtime mode, use function GetAmbientUserMode( BOOL& bMode ); returning TRUE for run mode and FALSE for design mode.
Hope this is what you meant and that it helps to you
|
|
|
|
|
Thanks a lot geo_m.
But Whenever I drag the component icon from toolbox to the form, in the OnDraw() event is drawn on the form as beveled window with "ATL 3.0 : ComponentName" written over it. I want to put the same icon that is in the toolbox instead of this, got it?
|
|
|
|
|
yep. Then you have to test if you are in the run-time mode or design time mode in the OnDraw (or store the result and only test it here)
If you will be in design time mode, you can draw your icon using DrawIcon method, or any other of your choice.
If you want to know which icon is on the VB toolbar, you can look into your resources, it is stored here, so you can access it and do with it whatever you like.
|
|
|
|
|
Thanks geo_m, you're the man!
|
|
|
|
|
Hi, everyone!
Please look at the following codes,
--------
template <class ForwardIterator>
inline void seq_delete (ForwardIterator first, ForwardIterator last) {
while (first != last) delete *first++;
}
vector<char*> v;
char* c1 = new char[20]; strcpy (c1, "Tim");
char* c2 = new char[20]; strcpy (c2, "Charles");
v.push_back (c1); v.push_back (c2);
seq_delete (v.begin(), v.end() );
// vector v is destroyed at the end of scope
--------
I think that since we use new[], so we should use delete[] other
than delete in the following line.
--------
while (first != last) delete *first++;
--------
Or else, memory leak will occur.
Am I correct?
Thanks in advance,
George
|
|
|
|
|
Yes, you are correct. Since the vector is using what I would call an "unmanaged pointer", the vector has no way of knowing it needs to delete the memory.
For the most part, this is considered bad style since any time elements are removed from the vector, you have to manage the pointers. Thus you have things like boost's ref pointer or stl's string implementation that handles all the management for you. Many times, you can use this "bad style" to your advantage but there is always an associated risk. But like all programming, there are associated risks with everything. It is just a question of managing those risks.
EDIT: I commonly use this "bad style" in situations where the vector is part of another class and is wholly owned by that class. Thus risks are greatly minimized. For the most part, I would never use this "bad style" with something that was directly exposed to other classes or the main program. (i.e. public class members or a global vector.)
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi, Tim buddie!
What means
--------
EDIT: I commonly use this "bad style" in situations where the vector is part of another class and is wholly owned by that class. Thus risks are greatly minimized. For the most part, I would never use this "bad style" with something that was directly exposed to other classes or the main program. (i.e. public class members or a global vector.)
--------
in your reply, can you show me an example?
I found the examples are better to make oneself understood when
expressing thoughts. I am a newbie.
Thanks in advance,
George
|
|
|
|
|
Trying to think of a simple one... *thinking*
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi, Tim buddie!
What is your meaning? I can not get your ideas?
Thanks in advance,
George
|
|
|
|
|
No, I was just trying to think of a simple example.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks, Tim buddie!
I am waiting for your nice example.
George
|
|
|
|
|
In MFC we can use: CString::GetBuffer() or GetBufferSetLength()
- muck with string - then CString::ReleaseBuffer() to work directly with the internal buffer.
In STL we can use s.reserve( .. ); s.data(); which I assume will work, but how do we set the new size. Calling s.reserve() when we are done makes some sense, but how do we set the new size. My reference for reserve() says it may or may not resize the internal buffer, but it doesn't sound like it sets the length.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
s.reserve(n) makes sure that the string length can grow to at least n characters without reallocations. It doesn't have effect to the actual string length. You can use s.resize() to set the string length. There's no equivalent to GetBuffer() /ReleaseBuffer() , you can't directy manipulate the characters in the internal buffer.
|
|
|
|
|
markkuk wrote:
There's no equivalent to GetBuffer()/ReleaseBuffer(), you can't directy manipulate the characters in the internal buffer.
Thanks, that's what I thought. This is a pity as you have to waist time and code copying an STL string to a C string and back again at times. eg. When you call a function which only accepts a C string as a parameter, and the callee has an STL string.
Thanks for your help.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
I noticed WTL programs often have implementation in the header files, I guess this is the convention ?
I noticed the option in VS.NET project creation to create .cpp files, but by defualt it is not checked.
I guess I should conform and implement in header files, correct ?
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|
|
Two reasons for that. First, with template classes, all the code has to be in a header file (well, technically that's not true, but most people do it that way). And second, when you use ClassView to add message handlers, it puts the code in the header file.
I personally hate this because it makes the header file a pain to maintain, and results in longer builds because you'll be changing header files all the time as you're developing.
--Mike--
The Internet is a place where absolutely nothing happens.
-- Strong Bad
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
I personally hate this because it makes the header file a pain to maintain, and results in longer builds because you'll be changing header files all the time as you're developing.
That is the big flaw in the design. It can be a huge problem for large scale projects.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hello,
I created a COM DLL. (with VC++.NET but this is not important).
And created some assembly the has a function, that create instance from the
COM class, and call some function from the COM object.
When I call the functions of the assembly as simple as possible, from some
console app, this is work.!
But if I do it via remoting, it isn't work!! and give this exception:
Unhandled Exception: System.InvalidCastException: QueryInterface for
interface ScreenCamaraASM.IScreenCapturing failed.
Server stack trace:
at ScreenCamaraASM.CScreenCapturingClass.GetNumber()
at RCServerNP.RCServer.GetScreenPicture() in d:\mydocs\visual studio
projects
\remotecommunication\rcserver\rcserver.cs:line 24
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(M
ethodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInC
ontext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMes
sage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgDa
ta, Int32 type)
at RCServerNP.RCServer.GetScreenPicture() in d:\mydocs\visual studio
projects
\remotecommunication\rcserver\rcserver.cs:line 21
at Testing.Class1.Main(String[] args) in D:\MyDocs\Visual Studio
Projects\Rem
oteCommunication\Testing\Class1.cs:line 36.
Please, any solution?
Thank's, Itay.
|
|
|
|
|
Hi, everyone!
Here is an example about the usage of
bind2nd. But I do not understand what the
function is doing. I have used MSDN to find
help, but still puzzled because there is only
a little of material on the topic.
Who can tell me what is the function doing in
the following example?
--------
vector<int> v;
// fill v with 4 6 10 3 13 2
int bound = 5;
replace_if (v.begin(), v.end(), bind2nd (less<int>(), bound), bound);
// v: 5 6 10 5 13 5
--------
Thanks in advance,
George
|
|
|
|
|
In this particular case bind2nd is function that uses comparison function (less by default) to compare any argument to value of 'bound'.
So for each element in v.begin() ... v.end() range replace_if calls bind2nd and if true returned it replaces element value with value of 'bound'
Your example:
vector v;
// fill v with 4 6 10 3 13 2
int bound = 5;
replace_if (v.begin(), v.end(), bind2nd (less(), bound), bound);
//////////////////////////////////////////
another way(not the best):
const int bound = 5;
for(vector::size_type i = 0, size = v.size();i< size;++i)
{
if(v[i] <= bound)
v[i] = bound;
}
+
|
|
|
|
|
Thanks, AlexO buddie!
George
|
|
|
|
|