|
OK. Thanks for your thoughts and replies.
My algorithm is not application specific (that I can see). I'll go ahead and post it here in case anyone else can benefit from it. It looks long, but it's mostly comments. The test case at the end works fine for me when I compile and run it with Digital Mars C++.
#include <string.h>
void memoryfill( void* target, char* pattern, size_t ptrnlen, size_t numRepeats )
{
char* trgt = (char*)target;
if( 0 == numRepeats )
{
;
}
else if( 1 == ptrnlen )
{
memset(target, *pattern, numRepeats);
}
else
{
memcpy(trgt, pattern, ptrnlen);
int snglbit=1;
int thisCnt = numRepeats >> 1;
while( thisCnt > 0 )
{
memcpy(trgt+ptrnlen*snglbit, trgt, ptrnlen*snglbit);
snglbit <<= 1;
thisCnt >>= 1;
}
char* endptr = trgt + ptrnlen*snglbit;
while( (snglbit >>= 1) > 0 )
{
if( snglbit & numRepeats )
{
memcpy(endptr, trgt, ptrnlen*snglbit);
endptr += ptrnlen*snglbit;
}
}
}
return;
}
<br>
#include <stdio.h>
<br>
int main()
{
char buf[1024];
memset(buf, 0, 1024);
memoryfill( buf, "Hello World_", 12, 19 );
printf("\n%s", buf);
}
|
|
|
|
|
This reminds me of how I create large test files. For example, if I wanted a file with 100,000 characters, I would open Notepad, type 10 characters, copy those and paste nine times (yielding 100 characters). Then I would copy those 100 characters and copy those nine times (yielding 1000 characters). I would repeat this two more times to get the final result, all from an initial 10 typed characters.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
That's exactly it, only base-2 instead of base-10.
|
|
|
|
|
Well, probably not the answer you were looking for but if you really want to do this in the most efficient way possible you are going to need to use assembly language and take advantage of the chip specific instructions. I have done this before for some built-in-self-tests for embedded hardware where the timing requirements were that all of the tests had to complete in under 1 clock cycle.
|
|
|
|
|
Thanks for the response. I'm sure you are correct if efficiency is the driving force.
I figured the best approach would be one that does a lot of what memcpy() already does: deals with all possible alignment issues, and once those are out of the way, uses the fastest native size (2, 4, or 8 bytes, depending on the processor) to do the guts of the transfer. Clearly, this is assembly language/processor specific kinds of stuff. Nevertheless, I had thought perhaps someone already had some good cross platform algorithm that would at least do the alignment stuff, then assume int was best for the rest of the transfer.
My approach is pretty good, except that it forces repeated dealing with alignment issues on every single call to memcpy(). Fortunately, it calls memcpy() a max of 63 times. I haven't spent many hours pondering this, but it MIGHT be that there is just no way around repeatedly dealing with alignment issues. If this is the case, then perhaps my algorithm is already optimum. I really don't know.
Thanks again for the response.
David
|
|
|
|
|
You might want to look for an open implementation of memcpy and then create your own version that does the same thing but excludes the alignment stuff, which you could then do once as a separate call. I don't know if the Rotor source code includes an implementation of memcpy for use on non-Windows systems, but it might be a place to start. (I know it does have other low-level C functions that have been reproduced, just not sure if memcpy is one of them.)
|
|
|
|
|
Interesting! Clever idea.
I probably won't do it just because I already have a workable solution, and don't want to spend the kind of time it would require. I was really just fishing, assuming someone out there already had an optimum portable algorithm. For my application, the maximum numRepeats will only be on the order of a few hundred, so the looping won't be severe; for sure won't justify the amount of time I'd spend writing an optimum algorithm. See http://www.codeproject.com/tips/optimizationenemy.asp?df=100&forumid=683&mpp=50&select=2267125&msg=2267125[^]
Thanks again.
David
|
|
|
|
|
|
I took a quick look at the source. It doesn't do any alignment; just the straight-forward
*(target++) = *(src++);
kind of thing. I suppose they're relying on the compiler to recognize the pattern, and substitute the appropriate idiom for memory copy on the selected platform. I guess if the compiler is smart enough, that's a good; well, a *portable* way to do it...
|
|
|
|
|
Ahh...I didn't really look at the source other than to verify that it was actually a memcpy implementation. Oh well...
|
|
|
|
|
Hello!
I am trying to change the width of the scrollbars of certain controls in a project I am developing.
It is funny enough, that if I am changing the Appearance settings in XP, the size of the scrollbars are changing.
I was trying to use the GetSystemMetrics Function. If I override it be the use of the Detours lib, and with passing the intended width, the sizes of the scrollbars remain as specified in the "Appearance settings".
How can I programatically change the Appearance settings for only one program? As it seams not working with the GetSystemMetrics
Thanx
Zoltan
-- modified at 14:05 Wednesday 10th October, 2007
The MoveWindow and SetWindowPos unfortunately does not solv the problem as that will make the arrows of the scrollbar to look squashed.
|
|
|
|
|
Standard scrollbars use the system metrics settings.
Scrollbar controls, however, are windows, so you can use
MoveWindow()/SetWindowPos() to resize them.
If you want control over the size, use scrollbar controls.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanx Mark!
That is true definitely! However - it seams I did not describe fully my problem.
If I do MoveWindow or SetWindowPos, the width may change but the arrow will become flat - I may change the width of the scrollbar from 16 to 32, but the height of the arrow will stay 16 and it makes it look "squashed", and that what I'd want to avoid.
Mark Salsbery wrote: Standard scrollbars use the system metrics settings.
which scrollbars are you referring to? The ones subclassed with CScrollbar? /not part of any control/
Zoltan
|
|
|
|
|
tortexy wrote: If I do MoveWindow or SetWindowPos, the width may change but the arrow will become flat
That's what you'll get if you want Windows to draw the control for you.
You may want to implement your own control
tortexy wrote: which scrollbars are you referring to? The ones subclassed with CScrollbar? /not part of any control/
Standard scroll bars are the ones you get when you specify the WS_HSCROLL/WS_VSCROLL
style(s) when creating a window. Without access to an HWND for those, you can't change
their size.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark!
Thanx for the help.
Are you familiar with the Theme or System metrics stuff?
As I said I have overrode the getSystemMetrics function. I was catching the functions for SM_CXVSCROLL, SM_CYHSCROLL, SM_CYVSCROLL,SM_CXHSCROLL. I could see it returning different values (the values as changed in the Display properties).
I have changed these also, but the widths of the scrollbars were as set in the Display settings.
I mean, why is that, if changing the Appearance at the "Display Properties", the appearance of the scrollbar changes, it increases its width and so on, but it is not possible to be done programaticaly.
Or if it is possible how to do it?
|
|
|
|
|
Does anybody know how to get windows vista to work with direct music to send MIDI messages...Direct music 2003 allows me to play samples but I want to modify the code...
Rance_Wilson
|
|
|
|
|
The project can recognise CString, but when I went to use CDatabase I got the error
CDataBase db;
do stuff with db....
'CDatabase' : undeclared identifier.
Do I need to include something? I thought since the project has MFC support it would automatically recognise CDataBase.
thanks,
sb
|
|
|
|
|
I'm not sure why you think the compiler would automatically recognize any
unknown types...
You probably need to include afxdb.h
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
how right you are! It worked.
thanks Mark.
sb
|
|
|
|
|
ns wrote: Do I need to include something?
Yes, read here (near the bottom) for what.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
but something is mentioned here : https://www.ittvis.com/services/techtip.asp?ttid=3346
Ajay
|
|
|
|
|
Did you understand the article? I'm not being nasty, that is a serious question. The short answer to your question is: Rebasing only affects memory allocation in that it can "sometimes" create a larger non-fragmented chunk of free memory by forcing DLLs to load into a different memory location. A larger chunk of contiguous free memory means a larger allocation request can be filled. That's the gist of what the Rebase section of the article says. If that still doesn't make sense, you need to do some learning on how processes and their support DLLs are loaded into memory, and how memory allocation is performed.
Judy
|
|
|
|
|
Hello Friends,
I am using win32 application. In that I hide the Application on Dialog Initialization and put the icon in the taskbar. I am using the Context menu in taskbar. Ans Want to show the window when someone choose the Exit option of the menu. But it show me the strange Error.
Error code = 0x000005B4 which means "This operation returned because the timeout period expired. "
I am using following code
LRESULT CALLBACK MyDialogProc(...)
{
ShowWindow(hWndDlg,SW_HIDE);
switch(message)
{
case WM_TASKMSG:
if(lParam == WM_RBUTTONDOWN)
{
POINT pt;
GetCursorPos(&pt);
TrackPopupMenuhmenuTrackPopup,NULL,pt.x ,pt.y,0,hWndDlg,NULL);
}
break;
case WM_COMMAND :
switch(LOWORD(wParam))
{
case ID_Exit:
if( ! ShowWindow(hWndDlg,SW_SHOWNORMAL) )
{
dError = GetLastError();
}
}
}
}
I search lot on google for this error but it show that this type of error comes with database(SQL Connection) only.And not getting any solution
Please Help me if u know the solution. Thnx in advance
|
|
|
|
|
GauranG33 wrote: I am using win32 application. In that I hide the Application on Dialog Initialization and put the icon in the taskbar. I am using the Context menu in taskbar. Ans Want to show the window when someone choose the Exit option of the menu. But it show me the strange Error.
Error code = 0x000005B4 which means "This operation returned because the timeout period expired. "
First, don't hide a window in the first line of a dialog proc. It will be called many times for many reasons. Also, I think calling ShowWindow could involve a recursive call to your dialog proc, which immediately hides the window again.
Nathan
|
|
|
|