|
find_if is a bad choice if the vector is sorted as you'll get linear performance instead of logarithmic (for the search). Use std::lower_bound instead.
Steve
|
|
|
|
|
Use std::lower_bound followed by std::vector::insert . e.g.
using namespace std;
vector<int> vec;
int newval = 5;
vec.insert(lower_bound(vec.begin(), vec.end(), newval), newval);
Steve
|
|
|
|
|
Thanks Steve,
This is exactly what I was looking for.
Avi.
|
|
|
|
|
You often need to add or remove from the end?
You need it only occational but in time critical situations?
You do need the guarantee that your items are stored in adjacent places?
(Double-use of &vec[0] as a C-Array for example)
Then use the vector /lower_bound Stephen Hewitt proposed
If you only need a sorted storage, you would be better off with set/multiset.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
I have written a server using CAsyncSocket functions
Create, Listen, Accept, Send, Close etc. similar to the EchoServer program from The Code Project.
I create a single Listening port using
m_Server_Connection.Create(Client_Port);
m_Server_Connection.Listen();
I accept connections using
m_Server_Connection.Accept(m_Receive[this_client]);
//m_Receive[client] is an array of six CAsyncSocket
Communication with a client is done using
m_Receive[this_client].Send(msg,strlen(msg));
or
m_Receive[this_client].Receive(pBuf,pBufsize);
My problem is, when a client disconnects the connection is closed but..
How do I determine which connection is closing when OnClose is serviced?
I only accept 6 connections and want to re-use the m_Receive[x] entry
|
|
|
|
|
OnClose() will be called for/on the socket object that closed. Maybe store the array index in the
socket class so you know which one to free up for reuse in the array.
You'll need your own socket class derived from CAsyncSocket and make an array of those instead
Mark
|
|
|
|
|
I cannot see how to link the array index to the socket.
I am using a derived class called MyCsocket similar to the type Jobin Wilson uses in - Socket Programming with MFC (part 1)
can you show an example of what you mean.
|
|
|
|
|
Depends on how and when you are creating MyCsocket object. If they are created ahead of time
(before a connection is made) then add a function to set the index later.
A more resource efficient way is to create the socket when a connection is made - from the OnAccept()
in the listener socket (this way you only create a MyCsocket object when needed). In that case
pass the index to the constructor and use Attach() to attach the SOCKET from the listener to the
MyCsocket object.
Mark
|
|
|
|
|
Thanx
|
|
|
|
|
Alternatively to an index you could give each socket (incoming connections) a status value. Something like UNCONNECTED, ACTIVE, DEAD... and cleanup in your server code all dead sockets from time to time. This has the advantage of handling TCP close properly (e.g. you can disconnect a socket and wait until the other side has received all pending data and closes its end).
Hope it helps.
M
|
|
|
|
|
Cool thanks!
You should maybe post your reply to cgb143 as well
Cheers,
Mark
|
|
|
|
|
Didn't I do that?
/Mark (aka Moak)
|
|
|
|
|
Hi,
I want to create a MPEG movie from a set of bitmaps(500+). How can I do this? Which technology should I use for this(DiretX etc)
Regards,
Hemant.
|
|
|
|
|
If you are prepared to save in AVI or WMV format instead of MPEG, there is a lot more information on CodeProject. CodeProject does not have much on MPEGs, probably because the format is not supported directly by MS.
When I wanted to save an AVI file, this article www.codeproject.com/bitmap/createmovie.asp[^] was very useful.
|
|
|
|
|
The Windows Media Format SDK works pretty well.
There is an MPEG 4 codec available as well as full WMA/WMV support.
Windows Media Downloads[^]
Mark
|
|
|
|
|
Hi,
Thanks for reply.
I just searched the MSDN for Windows Media format SDK. But says about only ASF format.
Here is para from MSDN SDK introduction
"The Microsoft® Windows Media® Format 9 Series Software Development Kit (SDK) enables developers to create applications that manipulate digital media stored in files conforming to the Advanced Systems Format (ASF) file structure"
It says nothing about MPEG. Is it still possible to use Windows Media format SDK.
Regards,
Hemant.
|
|
|
|
|
Yeah sorry support is limited....here's what the SDK says...
The Windows Media Audio and Video Codec Interfaces also enable access to some legacy
codecs, including Windows Media Video 7 and 8, Windows Media Screen 7, the older Microsoft
MPEG-4 codecs, and the Microsoft ISO MPEG-4 codecs.
Note This documentation does not cover these legacy codecs; it only covers the Windows
Media 9 Series and later codecs.
For older codecs, use the same procedures as when using the Windows Media 9 Series codecs,
however, remember that not all features are supported in all codecs. In addition, the MPEG-4
codecs are not supported in the video encoder DMO.
The codec is there but I've never tried actually writing a MPG/MPEG file with it though.
I suppose it writes an ASF format file compressed MPEG-4.
I do know it works - I use it extensively (for Windows Media).
I don't know of any FREE mpeg writers that don't violate someone's license.
MPEG Licensing[^]
Mark
|
|
|
|
|
You can make your movie file with avi and if you want to use it you can see MSDN for it I saw a good example on MSDN and also you can find examples on codeproject
|
|
|
|
|
Hello, I have to store a DATE type into the Registry. The problem is, i shall only use certain functions. One of these sets a Dword into the Registry. But when I load the value from Registry, the correct date wont be displayed. What did I do wrong ?
|
|
|
|
|
Checker2003 wrote: What did I do wrong ?
Without seing any code, it is impossible to answer...
|
|
|
|
|
Checker2003 wrote: What did I do wrong ?
You need to store it as REG_BINARY .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I have to ask different, can I convert a DATE into a DWORD, or do I have to use REG_BINARY as my good fellow told before ?
Thank you
|
|
|
|
|
A DWORD is long enough that you could write code to shove a date in there, I would think. If you're going to define your own format, then it's up to you what that is going to be.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: A DWORD is long enough that you could write code to shove a date in there, I would think.
Yep, DWORD is "32-bit unsigned integer" (not a double as the OP supposed):
20061016 < UINT_MAX (4294967295)
|
|
|
|
|
Since a DATE is actually just a double , you could potentially lose 99% of a day. In other words, if your DATE value was 39006.999988 (one second shy of midnight), storing that as a DWORD would only store the 39006 part, thus losing almost 24 hours. Make sense?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|