|
as i understand it, you have several arrays, one per year, and want to find them by the year number ; for this, the standard library implements the std::map<> class.
as I imagine, the arrays may not have the same size each, so you could be using such a map :
std::map< int, std::vector< int > > mapYearWithVector;
is this true ?
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20] | soon : [VisualCalc 3.0]
|
|
|
|
|
I'm sure that this cannot be done using conventional arrays.
The way I would do it would be to use a linked list. That way, the years could be in any order, and years could be missed out if required.
class node
{
private :
int year;
int value;
node * pointToPrevious;
public :
node()
{
}
node(int y, int v, node * p)
{
year = y;
value = v;
pointToPrevious = p;
}
};
For fuller notes on linked lists as I teach it, please email me : simon.cornish@tesco.net
Regards
Simon
|
|
|
|
|
In my application i get body(IHTMLElement) and try to reset onclick event like javascript:alert('ok');
There is little document of IHTMLElement->put_onclick(VARIANT) from MSDN, but the line
CComPtr<ihtmlelement> pBodyElement;
//other codes
pBodyElement->put_onclicke(VARIANT("javascript:alert('ok');"));
doesnot work.
Would you please show me why,or show me some samples?
thanks advance.
|
|
|
|
|
Hi,
I am using CRecordset to retrieve data from SQL server but i found there is a performance issue with retrieving 173 rows of data from the data. I then narrow it down to MoveNext() causes the performance to be slow. Can someone please help?
Here is the code, simple but slow in performance.
CString sSql;
CRecordset rs(&gGlobalLHdb);
sSql = "SELECT * FROM metrics";
if (!sSql.IsEmpty())
{
rs.Open(CRecordset::forwardOnly, _T(sSql));
while(!rs.IsEOF())
{
// metric_name
CString s1;
s1 = "metrics_name";
CString sRetVal1;
rs.GetFieldValue(s1,sRetVal1);
rs.MoveNext();
}
rs.Close();
thank you so much,
Sue
|
|
|
|
|
I have yet to understand why I should choose Tabbed Controls over Property Sheets and vice-versa. Are there advantages of one over the other? How do they differ from a user's point of view?
Any short answers to these questions?
Thanks in advance.
P.S. The answers may be obvious, but I somehow missed the outstanding
diferences.
|
|
|
|
|
I have SnapStream which records TV shows in MPG then compresses to WMV format. I also have an iPod Video which wants MP4. Unfortunately I can't find anything that will automatically, or from a command line batch file, find new recordings and convert them. Hmm, this sounds like a good project to start on.
I'm pretty well versed in C++ and know C# just a little bit less. I searched the articles for a library/API/SDK to interface with but didn't really find anything useful. Can anyone direct me to some articles, or SDKs, to help get me started writing my own file conversion program? Am I on crack thinking I can just jump into multimedia conversion with only experience writing MSI installs and network programs?
Thanks in advance for any knowledge of this you can impart to this humble dev.
|
|
|
|
|
DirectShow, which is part of DirectX.
davedoc wrote: Am I on crack thinking I can just jump into multimedia conversion with only experience writing MSI installs and network programs?
Perhaps, only time will tell.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks. I've downloaded and installed.
Onto happy reading/learning...
|
|
|
|
|
How do you like SnapStream? I'm still using the crappy stuff that came with an ATI All-In-Wonder card. It works okay, but there's stuff about it that I dislike. The TV listings app is to closely tied to TV viewing. The dialog for recordings should be modeless instead of modal. Simple stuff, but it bugs me. Thanks.
Chris Meech
I am Canadian. [heard in a local bar]
Remember that in Texas, Gun Control is hitting what you aim at. [Richard Stringer]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
It's worth every penny of the $50 I paid for it 3 years ago. I've been using Snapstream since their late 2.x days, it's now at 4.0, and I've been in love with the software ever since. I recommend it to all the TiVo users I know Once you pay for the software...that's it. No monthly subscriber charge.
I saw some bugs at the 2.x level but the support forum they have on their site has always been quick to respond. I'm still running the latest 3.x build and it's rock solid. The upgrade to 4.x will cost me another license purchase and I haven't upgraded this yet.
I stream TV (news channel) to my work using Snapstream and have it playing in the background.
|
|
|
|
|
Thanks. Good stuff to hear.
Chris Meech
I am Canadian. [heard in a local bar]
Remember that in Texas, Gun Control is hitting what you aim at. [Richard Stringer]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
I have a CEdit which I drawn a custom background for in an WM_PAINT handler. it works great until I edit, then it draws like any other edit control. If I put an Invalidate() call in my WM_CHAR handler, it draws the background properly, and draws the text all wrong. What should I be doing here ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Not that I have ever done it, but you could try drawing the background in OnEraseBkgnd, and in OnCtlColor call pDC->SetBkMode(TRANSPARENT) and return a NULL brush so that the text is drawn transparently over your background.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Sounds like a great idea, I'll try that. I was going to go for the Erase Background, but I hadn't thought of how to stop the control drawing over it. The edit control apparently draws outside of WM_PAINT a LOT.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I am using ASyncSockets for TCP/IP comms. My program (a client) recently crashed when another program sent excessive data via a server . Can I control data flow, if so how?
I could try to fix the 'memory overflow' by increasing the buffer sizes, but I fear this will only delay the crash until the larger buffer overflows. Suggestions welcome
Thanks
CGB
|
|
|
|
|
Can you clarify what you mean by 'memory overflow' a little bit more...
When you're using CAsyncSocket you get a notification whenever there are incoming data pending to be read. You read this data with a call to CAsyncSocket::Receive, providing a pointer to a buffer where you want the received data and a size of the buffer in question. If you provide the wrong buffer size I would guess the application would crash.
The data received in the buffer could be stored in a dynamic queue for incoming messages or whatever suits your needs.
If you run out of heap it's another problem that should be solved by a protocol that supports some kind of flow-control in order to inform the sender that the receiver is busy.
Since you mentioned TCP I assume you're not using UDP.
--
Roger
It's supposed to be hard, otherwise anybody could do it!
|
|
|
|
|
Unfortunately I am unable to clarify the 'memory overflow' further as this is the only information I was given and the problem was discovered by someone else.
I shall try to get more details if I am unable to resolve the problem using the advice I have received from yourself and Jorgen.
Under normal conditions, everything runs OK and memory allocation is ample.
The problem occurred while the 'someone else' was developing his own code and got into an error condition that caused a continuous stream of data to be sent to my program. I am now attempting to make my code more robust, to take care of the previously unforseen.
Thanks
cgb
|
|
|
|
|
As previously said this looks like a memory handling problem and not like a socket problem.
If you can not reproduce it with a test case, I suggest adding a crash report[^] to your application. In case your program crashs again, it then will write the exact location (instruction pointer and other registers) to a file and you will be able to pinpoint the bug. Hope it helps.
/Moak
|
|
|
|
|
cgb143 wrote: . Can I control data flow, if so how?
Yes. Just don't read the data as soon as it arrives. The effect will be that the operating system will stop acking the TCP packets from the originating klient. Basically, the faster you read, the faster the other side can send.
cgb143 wrote: I could try to fix the 'memory overflow' by increasing the buffer sizes, but I fear this will only delay the crash until the larger buffer overflows. Suggestions welcome
It sounds like you need a better buffering scheme. First of all, you should consider using a dynamic buffer for storing your incoming data. Perhaps a queue of buffers? So whenever a buffer is full, create a new one and append it to the queue, and write the incoming data to that one. When you've "emptied" a buffer (front of queue) by reading all the data in it, remove it from the queue. If your application needs speed, you can always keep a pool of preallocated and unused buffer from which you take buffers whenever you need a new, and into which you put old and used buffers. Your code may also need to expand the pool of unused buffers, should you run out of buffers.
You should also manage the data flow better. A rule of thumb is to not read data at a faster rate then you can process it. That way it will be harder to perform a Denial of Service attack on your application.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
Thanks for the advice, I'll experiment and see what works best.
If I slow down my 'read rate' can this cause a problem to the sender. What I mean is will Windows prevent the sender from .Send()ing data to his socket (by returning an error) or will Windows buffer the data at a lower level.
I think modifying my buffering scheme will prove to be best.
Thanks
cgb
|
|
|
|
|
Yes, the read rate will "trickle back" to the sender. The TCP protocol is designed such that if the receiver stops sending back ack packets at the same rate as data packets are sent to it, the data flow will slow down, or even stall if there's a complete stop.
> I think modifying my buffering scheme will prove to be best.
I really suggest applying both methods (reading and buffering). Especially so if the server will be connected to the Internet. The last thing you want is vulnerability to denial of service attacks, as it may render the entire machine unusable. At the very least, you should have some upper ceiling on your buffers, and just refuse to accept more data than can be buffered.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
Hi everyone:
I need to use dynamic array in my program. I know in C I can use malloc and realloc to do this. I tried this way, and following is the piece of the code
//////////
VERTEX_BUFFER * vertex_list;
if(vertex_list == NULL){
vertex_list = (VERTEX_BUFFER *)malloc(sizeof(VERTEX_BUFFER));
vertex_index++;
}
else
realloc(vertex_list, (sizeof(VERTEX_BUFFER)) * (++vertex_index)); // reallocate memory
//////////
But it gave an error message everytime the program execute the realloc function.
Could somebody give me a solution to dynamic array please??? Or tell me why this doesn't work.
Thanks in advance
Asura
|
|
|
|
|
Ming Luo wrote: if(vertex_list == NULL){ vertex_list = (VERTEX_BUFFER *)malloc(sizeof(VERTEX_BUFFER)); vertex_index++; }
The code you're showing here has an uninitialized pointer (vertex_list). I'm thinking it is initialized properly in your app, and this example is just a sample to highlight your problem. But have you checked to see that you are indeed initializing vertex_list to NULL? If not, it will contain a non-NULL garbage value, which realloc won't like one bit.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
In addition to the uninitialised variable, realloc may (and often does) return a new pointer, if the block of memory moved. If it fails, then it returns 0. A safe way of reallocating would be:
VERTEX_BUFFER *new_buffer = (VERTEX_BUFFER *)realloc(vertex_list, (sizeof(VERTEX_BUFFER)) * (++vertex_index));<br />
if (new_buffer){<br />
vertex_list = new_buffer;<br />
}else{<br />
...<br />
}<br />
Note that because it may shift blocks around in memory, realloc can be a very slow function to call. Usually in this case it's customary to double the size of the allocation each time - it can be proved that over time the amortised cost of realloc tends to O(1) with the doubling approach, though it does mean you allocate a lot of memory. The STL containers (std::vector etc) do this as far as I can tell. Might be worth looking into using an STL container for your code too; it's usually pretty good at this kind of thing.
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
Ah yes, of course you are right. The old realloc() "trap" is best avoided.
--
Pictures[^] from my Japan trip.
|
|
|
|