|
Thanks Jerome for your attention. You know i have written several functions for Adding,Subtracting,Multiplying,....
huge numbers, my functions look like :
CString ADD(CString s1,CString s2)
CString SUB(CString s1,CString s2)
...
CString TO_BINARY(CString s1)
you see i have a function
as shown above TO_BINARY , which means that it does smth like this (just example)
CString g = ToBinary("13");//so g="1101"
and this function is too slow when instead of "31" i enter
number with 100 digits or more, Could you please give me any idea if i can use theses 0x000,... or smth similar to make my algorithm faster
Regards
m0n0
|
|
|
|
|
The simplest algorithm I can think of - and it does not mean it is the most efficient - is the following
Is the number odd, insert a "1" at the beginning of the string, a "0" otherwise
Divide the number by two (integer divide) (or you can substract 1 or 0 before you do the divide so you do not have to bother with floats)
If the result is 0, exit else start again
The division by two is usually very efficient on binary numbers (operator >> ) but if your numbers are stored as strings it is irrelevant.
Let me know! Good luck!
|
|
|
|
|
Hy!
Please someone tell me how can I conrol with a spin control float numbers in C++ .NET? I want to change values from 0 to 1. I attached an edit box as buddy for the spin control, but I can't control float numbers.
|
|
|
|
|
Hi!
Please consider this generic scenario:
Let's say that I have a GUI thread with a main window containing some kind of child list window. I fire off a worker thread, which perform some lengthy operations, to keep the GUI responsive to user interaction. At some stages, which can occur with both high- and low frequnency, the worker thread wants to communicate a textual description of the current stage to the GUI thread.
Today I implement this in a rather, as I feel, unnecessary complicated way.
I wonder if it would be safe to do it this simple instead:
1. The worker thread wants to communicate a new text to the GUI.
2. The worker thread allocates memory for the text character buffer.
3. The worker thread copies the text to the buffer.
4. The worker thread will not access the allocated memory again.
5. The worker thread posts a notification window message to the GUI.
6. The notification window message holds a pointer to the allocated text in its WPARAM.
7. The GUI thread adds the text to the list.
8. The GUI thread frees the allocated memory.
Now, what can go wrong here and what would be the impacts of that?
As I see it, the only possibility of a memory leak is that the GUI thread message queue is filled, so that no more pointers to allocated memory gets through. But this should be "impossible", since the message queue is only limited by the available RAM - or isn't it?
The upside of this method is that it requires no locking or synchronization and minimal efforts in both worker and GUI thread.
Comments?
--
The Blog: Bits and Pieces
|
|
|
|
|
I've used this exact approach. There is nothing wrong with what you are doing.
Johann Gerell wrote:
the only possibility of a memory leak is that the GUI thread message queue is filled
I found the following in the MSDN for PostMessage() [^]. There is a default limit of 10,000 messages that may be posted to a window using PostMessage() . If your call to PostMessage() fails, you should delete the memory allocated for the string yourself.
PostMessage() is nice because access to the message queue is synchronized for you. If the 10,000 message limit is a problem, you will need to create your own communication mechanism between the two threads. Here's a simple example:
CTypedPtrList<CPtrList,char *> Queue;
CCriticalSection QueueCS;
char *string = NULL;
QueueCS.Lock();
if (!Queue.IsEmpty()) string = Queue.RemoveHead();
QueueCS.Unlock();
free(string);
QueueCS.Lock();
Queue.AddTail(strdup("Message string"));
QueueCS.Unlock(); The two threads communicate using a simple queue of pointers to strings. The critical section safeguards access to the queue. The worker thread allocates the strings on the heap using strdup() , and the GUI thread deallocates them using free() .
The only complication with this approach is that you must have the GUI thread poll the queue at intervals to update the screen. For example, using a WM_TIMER handler, you could have the GUI thread update the screen at one second intervals.
Another possibility is to reduce the number of strings sent by the worker thread. If the strings being sent are a simple progress update ("Processing for 5 seconds...", "Processing for 6 seconds...", and so on), you only need to send strings when the time changes.
Software Zen: delete this;
|
|
|
|
|
Hi
In functions like PreTranslateMessage you get a pointer to a MSG structure which includes some UINT message. How can I resolve that number into plaintext (the name of the message) e.x. "WM_KEYDOWN" so that I have an understandable TRACE output?
Thanks & Bye,
T.T.H.
|
|
|
|
|
please refer winuser.h
where you can find the numeric values of each windows message
example:
#define WM_COMMAND 0x0111
#define WM_SYSCOMMAND 0x0112
#define WM_TIMER 0x0113
#define WM_HSCROLL 0x0114
#define WM_VSCROLL 0x0115
#define WM_INITMENU 0x0116
#define WM_INITMENUPOPUP 0x0117
#define WM_MENUSELECT 0x011F
#define WM_MENUCHAR 0x0120
#define WM_ENTERIDLE 0x0121
|
|
|
|
|
Hi !
I'm sure this is a stupid question, but, if I do this :
char Buffer[10];
std::cin >> Buffer;
How can I make sure that the input won't be longer than the buffer ?
Jérôme
|
|
|
|
|
Use
std::cin.read(Buffer,sizeof(Buffer)); (caveat, this does not append and null terminating character.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
|
|
hi..
I am developing an application which requires me to collect voice spoken on telephone (i.e. outgoing call), record it and play it back later..
The numbers dialed on the telephone should appear on the screen.. Can someone pls tell me how to go about this.. basically what i want to know is how to communicate with the USB driver ..(phone is connected to USB port using and adapter.)
I also want to know how to record voice spoken on telephone..
Thanx
mpal
|
|
|
|
|
|
I am New to CodeProject, and have used the Article Wizard to create an article and noticed no feedback is given...
This article is based for Beginners using File I/O... I was wondering if some of you would take time to review this short tutorial and give me feedback and vote if its suitable for Beginners.
http://www.codeproject.com/useritems/FileIOTutorial.asp[^]
Thanks Ahead of Time,
~~HDPerformance808.
Contact Information:
Email: HDPerformance808@hotmail.com
AIM: HDPerformance808
|
|
|
|
|
how can I display the data that I get from the USB2.0 port? The data from the USB port continuously is in the "int buffer[1000];" I would like to use the PolyLineto(pt,1000) function to draw the line ; pt is defined as CPoint pt[1000],
for(int i=0;i<1000;i++)
{
pt[i].x=i;
pt[i].y=buffer[i];
}
if I use the "pt[i].y=buffer[i]; " sentence ,every time the CPU will do an extra copy work, it will waste the CPU time.
Are there any good methords that I don't need to copy the buffer data to the pt[i].y array?
thanks
zhenyuanwu.
|
|
|
|
|
hi,
Use memcpy fucntion it will copy the whole buffer at a shot.
all the best
Hasan.
hasansheik@yahoo.co.in
hasansheik@lycos.com
|
|
|
|
|
I'd like to setup my application so it can only run from the CD it's to be distributed on.
Can someone offer suggestions?
Thanks
Rich.
|
|
|
|
|
Simply follow this logic.
- Get the path of your Application using [
GetModuleFilename ]api.
- Now extract the Directory from the this path using [
_splitpath ]
- Check Is this directory is CD drive?[
GetDriveType ] if yes run the program else......
This logic may not work well when some one is using
S/W like vitural CD,Nero Image Drive
etc.
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
Hi,
I need to change the background colour of checkbox. Is there anyway by which this can be accomplished.
Thanks for any help
Regards
Vikram Attiganal
|
|
|
|
|
Follow these step:-
1. Make the CheckBox control OWNERDRAWN either by selecting OWNER DRAWN property from property window or using [your button object]::ModifyStyle(0,BS_OWNERDRAW).
2.Handle WM_CTLCOLOR message to set background color of control.
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
I've developed an application that receives UDP messages through
an Ethernet connection. This application run on W2K and I've uses
some SDK functions to manage sockets.
Mine problem is the following:
the application runs properly on PCs where there are Visual Studio
and Win SDK installed.
When I run the application on a PC without that applications,
it is not able to manage fragmented UDP packets. It receives only
small UDP packets but not larger ones (the select made on sockets
doesn't return when a packet is received).
I've also verified to OS version and the service packs installation
but it seems to not be the problem.
How can I solve this problem ?
Is it due to some DLL not available in the PC ?
Is it due to some sockets, or network card settings ?
Thanks a lot
|
|
|
|
|
Dears,
How can i draw a normal rectangle(not focus rectangle ) and circle using CDC class. I mean to say which methods are to be used?
|
|
|
|
|
|
In the project,there are serveal DocTemplate,How to save all the documents of diffferent Doctemplate into one file
|
|
|
|
|
Iam developing an excel like application similar to the AlxGrid which is found in the site
http://www.alxsoft.narod.ru/ENG/alxgrid.htm
When we have millions of data displayed in the grid, the process of selection is quite slow..its actually selecting cell by cell and hence the performance of the grid is quite slow....
can anyone help me out with this..
|
|
|
|