|
Chris Losinger wrote: 2. from those 1000 bytes, generate an SHA1 hash.
3. store the hashes, file size, and file names in a list
Why would you want to waste all those cpu cycles by calculating a SHA1 hash? If you know that the maximum number of bytes you're going to read is 1000 then you could have used an inexpensive hashing algorithm... there are dozens of inexpensive hash algorithms that will have a collision probability of zero within 1000 bytes. Your application would probably have a huge performance boost. Not to mention... the SHA1 hash will produce 20 bytes of data to store... you could reduce your database size by 50% just by moving to a more efficient algorithm.
Were you initially planning on hashing the entire file or something?
Best Wishes,
-David Delaune
|
|
|
|
|
it's actually an MD5, but can be switched to SHA1 or whatever, at compile time. (wrote the OP from memory, forgot the default).
Randor wrote: If you know that the maximum number of bytes you're going to read is 1000 then you could have used an inexpensive hashing algorithm.
probably. but the goal was to avoid collisions while using a hash method that was built into the .Net framework. this was a quick utility project. and really, calculating MD5 on 1K is definitely not the bottleneck here; the file scanning and open/read/close totally dominates the process - especially when those files are on a network drive somewhere.
Randor wrote: Were you initially planning on hashing the entire file or something?
actually, yes. (and that's what happens when the 1K scan finds matches). the partial hash pre-scan was a later addition, and i just reused the hash stuff that was already written instead of coming up with a new method.
modified 25-Apr-12 7:48am.
|
|
|
|
|
Hi friends,
I'm trying to create My own service for .exe.
my service create function successfully creates service but when i try to start to that service
then it gives error code 1053 which is ERROR_SERVICE_REQUEST_TIMEOUT. also i saw that startservice() fun goes in waiting for 30seconds
and then gives error 1053.
pls help,
here is my code for ur ref...
hServiceMGROpen=OpenSCManager(serverName,SERVICES_ACTIVE_DATABASE,SC_MANAGER_ALL_ACCESS);
if(hServiceMGROpen!=NULL)
{
hServiceOpen=OpenService(hServiceMGROpen,"myService",SERVICE_ALL_ACCESS);
if(hServiceOpen!=NULL)
{
succStart=StartService(hServiceOpen,0,NULL);
if(succStart)
{
printf("Service starts successfully ");
}
else
{
DWORD err=GetLastError();
printf("Error %d",err);
}
}
}
Thanks in advance...!!!
Sangam
modified 24-Apr-12 5:46am.
|
|
|
|
|
What does it mean:
here is my code for ur ref...
Anyway, ERROR_SERVICE_REQUEST_TIMEOUT, means that your ServiceControlHandler (or whatever name you have used to register handler callback) is not responding fast enough to the setvice start request, blocking StartServiceCtrlDispatcher. Or you did not call StartServiceCtrlDispatcher at all.
If you have to perform some lenghty procedure when the service starts, do it in the thread, or after setting service start status.
JohnCz
|
|
|
|
|
here is my code for ur ref means
i'm trying to show you that what i have done
|
|
|
|
|
Hi,
Where is your code?
Another thing: Could you lease refrain from using cryptic code like "ur ref means"? I would really appreciate it, since to understand it I need translation to English.
JohnCz
|
|
|
|
|
hServiceMGROpen=OpenSCManager(serverName,SERVICES_ACTIVE_DATABASE,SC_MANAGER_ALL_ACCESS);
if(hServiceMGROpen!=NULL)
{
hServiceOpen=OpenService(hServiceMGROpen,"myService",SERVICE_ALL_ACCESS);
if(hServiceOpen!=NULL)
{
succStart=StartService(hServiceOpen,0,NULL);
if(succStart)
{
printf("Service starts successfully ");
}
else
{
DWORD err=GetLastError();
printf("Error %d",err);
}
}
}
this is my code....!!!!
please findout problem....
|
|
|
|
|
I have dll that export funtion and on of the parameters is C-style strings a serial number.
extern "C" int __stdcall calc(char *SerialNumber)
The parameters can be come from VB, C#, C++ , C
I want to make som basic indata validation check that C-style is good kondition. That point is
not pointing at null and that the array is null-terminated. Somebody can point me in the right
direction. I don't want buffer over flow with staring to handel the string. Code sample?
|
|
|
|
|
Why don't you perform the input validation inside your DLL's function?
Veni, vidi, vici.
|
|
|
|
|
Hi, I am using mpi and cuda which is basically like a c programming. Just confused about the pointers here. Some help would be appreciated.
my cuda code
#include <stdio.h>
__global__ void add(int *devarray, int *devsum)
{
int index = blockIdx.x * blockDim.x + threadIdx.x;
*devsum = *devsum + devarray[index];
}
extern "C"
int * run_kernel(int array[],int nelements)
{
int *devarray, *sum, *devsum;
sum =(int *) malloc(1 * sizeof(int));
printf("\nrun_kernel called..............");
cudaMalloc((void**) &devarray, sizeof(int)*nelements);
cudaMalloc((void**) &devsum, sizeof(int));
cudaMemcpy(devarray, array, sizeof(int)*nelements, cudaMemcpyHostToDevice);
add<<<2, 3>>>(devarray, devsum);
cudaMemcpy(sum, devsum, sizeof(int), cudaMemcpyDeviceToHost);
printf(" \nthe sum is %d\n", *sum);
cudaFree(devarray);
cudaFree(devsum);
return sum;
}
This function returns int * as sum.
my MPI code
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ARRAYSIZE 2000
#define MASTER 0
int data[ARRAYSIZE];
int main(int argc, char* argv[])
{
int numtasks, taskid, rc, dest, offset, i, j, tag1, tag2, source, chunksize, namelen;
int mysum;
long sum;
int update(int myoffset, int chunk, int myid);
char myname[MPI_MAX_PROCESSOR_NAME];
MPI_Status status;
double start = 0.0, stop = 0.0, time = 0.0;
double totaltime;
FILE *fp;
char line[128];
char element;
int n;
int k=0;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
MPI_Comm_rank(MPI_COMM_WORLD,&taskid);
MPI_Get_processor_name(myname, &namelen);
printf ("MPI task %d has started on host %s...\n", taskid, myname);
chunksize = (ARRAYSIZE / numtasks);
tag2 = 1;
tag1 = 2;
if (taskid == MASTER){
fp=fopen("integers.txt", "r");
if(fp != NULL){
sum = 0;
while(fgets(line, sizeof line, fp)!= NULL){
fscanf(fp,"%d",&data[k]);
sum = sum + data[k];
k++;
}
}
printf("Initialized array sum %d\n", sum);
offset = chunksize;
for (dest=1; dest<numtasks; dest++) {
MPI_Send(&offset, 1, MPI_INT, dest, tag1, MPI_COMM_WORLD);
MPI_Send(&data[offset], chunksize, MPI_INT, dest, tag2, MPI_COMM_WORLD);
printf("Sent %d elements to task %d offset= %d\n",chunksize,dest,offset);
offset = offset + chunksize;
}
offset = 0;
mysum = run_kernel(&data[offset], chunksize);
printf("Kernel returns sum %d", mysum);
for (i=1; i<numtasks; i++) {
source = i;
MPI_Recv(&offset, 1, MPI_INT, source, tag1, MPI_COMM_WORLD, &status);
MPI_Recv(&data[offset], chunksize, MPI_INT, source, tag2,MPI_COMM_WORLD, &status);
}
MPI_Reduce(&mysum, &sum, 1, MPI_INT, MPI_SUM, MASTER, MPI_COMM_WORLD);
printf("\n*** Final sum= %d ***\n",sum);
}
if (taskid > MASTER) {
start= MPI_Wtime();
source = MASTER;
MPI_Recv(&offset, 1, MPI_INT, source, tag1, MPI_COMM_WORLD, &status);
MPI_Recv(&data[offset], chunksize, MPI_INT, source, tag2,MPI_COMM_WORLD, &status);
mysum = run_kernel(&data[offset], chunksize);
printf("\nKernel returns sum %d ", mysum);
stop = MPI_Wtime();
time = stop -start;
printf("time taken by process %d to recieve elements and caluclate own sum is = %lf seconds \n", taskid, time);
dest = MASTER;
MPI_Send(&offset, 1, MPI_INT, dest, tag1, MPI_COMM_WORLD);
MPI_Send(&data[offset], chunksize, MPI_INT, MASTER, tag2, MPI_COMM_WORLD);
MPI_Reduce(&mysum, &sum, 1, MPI_INT, MPI_SUM, MASTER, MPI_COMM_WORLD);
}
MPI_Finalize();
}
Now here mysum = run_kernel(&data[offset], chunksize);
gets the sum and stores into mysum.
Here mysum should be pointer, iguess but then
MPI_Reduce(&mysum, &sum, 1, MPI_INT, MPI_SUM, MASTER, MPI_COMM_WORLD);
does not work properly and system throws memory error.
here is the output of above code -
MPI task 2 has started on host 4
MPI task 3 has started on host 4
MPI task 0 has started on host 4
MPI task 1 has started on host 4
Initialized array sum 9061
Sent 500 elements to task 1 offset= 500
Sent 500 elements to task 2 offset= 1000
Sent 500 elements to task 3 offset= 1500
run_kernel called..............
the sum is 10
Kernel returns sum 159300360 time taken by process 2 to recieve elements and caluclate own sum is = 0.290016 seconds
run_kernel called..............
the sum is 268452367
run_kernel called..............
the sum is 10
Kernel returns sum 145185544 time taken by process 3 to recieve elements and caluclate own sum is = 0.293579 seconds
run_kernel called..............
the sum is 1048
Kernel returns sum 156969736 time taken by process 1 to recieve elements and caluclate own sum is = 0.297599 seconds
Kernel returns sum 152148496
*** Final sum= 613604136 ***
The final sum and initialized sum is not matching.
Any idea what is going wrong?
Thanks
|
|
|
|
|
hello guys... I am trying to load a bitmap into the picture control. Well when I debug, I see that the picture gets loaded but it does not show onto the control. I load the first bitmap at design time like this: Properties->Image->IDB_BITMAP1 . Then to load second image, I write following code in the click event of button. Here is what I am trying.
void CMyAppDlg::OnBnClickedNext()
{
HBITMAP bitmap [2];
bitmap[1] = ::LoadBitmapW(NULL, _T("All_The_Path\\Resources\\quaid.bmp"));
bitmap[0] = ::LoadBitmapW(NULL, _T("All_The_Path\\Resources\\Allama.bmp"));
if(CurrentImage == 0) {
m_Picture.SetBitmap(bitmap[1]); CurrentImage = 1;
}
else if(CurrentImage == 1)
{
m_Picture.SetBitmap(bitmap[0]); CurrentImage = 0;
}
}
What am I doing wrong? Thanks for any input.
This world is going to explode due to international politics, SOON.
modified 24-Apr-12 5:32am.
|
|
|
|
|
|
Thanks for the link. So I know another way for task.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
What happens to your HBITMAP variable when the function returns?
|
|
|
|
|
This is what I did.
CString strFileName = _T("All_The_Path\\Resources\\quaid.bmp");
bitmap[0] = ::LoadBitmapW(NULL, strFileName);
But I should have done this.
CString strFileName = _T("All_The_Path\\Resources\\quaid.bmp");
bitmap[0] = (HBITMAP)::LoadImage(NULL, strFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
Thanks for your time.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Yeah, but what SandipG was getting at is you have a memory leak - you load both images each time the button gets pressed.
You're better off making HBITMAP bitmap[2]; a member variable of the dialog instead of local variables in the button press-code. Then you load both images in OnInitDialog.
In the button-press handler you work out which image to display then display it.
That way, you only call LoadImage once per image.
|
|
|
|
|
Thanks for this useful tip.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
I was working in Windows Vista, and I moved the project over to XP to create the setup and deployment program.
I guess on the XP, I have some small details to fix. At first I thought it was just a Vista thing, I looked up the function, at it is Vista and up.
Not sure how to proceed on this, looking for suggestions.
Is there a way to use the ex and non ex version of the function, and to somehow keep them seperate?
|
|
|
|
|
You can check the version of the OS, and for XP, use the non-ex version.
Then for Vista and above, use GetProcAddress()[^] to dynamically link to the ex version at run time.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
oh, so thats how you do it.
Thanks Richard
|
|
|
|
|
Actually is not as easy as it looks.
Unless you really need to retrieve localized version info size, use GetFileVersionInfoSize instead GetFileVersionInfoSizeEx. GetFileVersionInfoSize is available starting with Windows 2000. You do not have to call LoadLibrary and GetProcAddress since your module (exe) is linked implicitly with Version.lib.
To write robust code you would have to write more than simple GetProcAddress.
If you really want to use both, depending on the operating system, you will have to retrieve proc address depending on OS version and load appropriate procedure address, since Version.lib contains both: ASCII and UNICODE versions of the functions.
If your app is built as ANSII you would have to use ANSI version of the function: GetFileVersionInfoSizeExW or GetFileVersionInfoSizeW depending on what system your app is running on.
For unicode build you will have to explicitly request UNICODE versions: GetFileVersionInfoSizeExW or GetFileVersionInfoSizeA.
Something like this:
void GetFileVersionLenInfo()
{
OSVERSIONINFO osvi = {sizeof(OSVERSIONINFO)};
DWORD dwHandle = 8000;
DWORD dwVer = 0;
GetVersionEx(&osvi);
HINSTANCE hInst = NULL;
#ifdef _USE_EXPLICIT
typedef DWORD (CALLBACK* lpfnGETFILEVERSIONINFOSIZEEX)(DWORD, LPCTSTR, LPDWORD);
typedef DWORD (CALLBACK* lpfnGETFILEVERSIONINFOSIZE)(LPCTSTR, LPDWORD);
hInst = LoadLibrary(_T("VERSION.dll"));
if(osvi.dwMajorVersion > 5)
{
#ifdef UNICODE
lpfnGETFILEVERSIONINFOSIZEEX lpfnGetFileVersionInfoSizeEx = (lpfnGETFILEVERSIONINFOSIZEEX)GetProcAddress(hInst, "GetFileVersionInfoSizeExW");
#else
lpfnGETFILEVERSIONINFOSIZEEX lpfnGetFileVersionInfoSizeEx = (lpfnGETFILEVERSIONINFOSIZEEX)GetProcAddress(hInst, "GetFileVersionInfoSizeExA");
#endif // UNICODE
dwVer = lpfnGetFileVersionInfoSizeEx(FILE_VER_GET_NEUTRAL,
_T("C:\\Program Files\\Beyond Compare 2\\BC2.exe"),
&dwHandle);
return;
}
#ifdef UNICODE
lpfnGETFILEVERSIONINFOSIZE lpfnGetFileVersionInfoSize = (lpfnGETFILEVERSIONINFOSIZE)GetProcAddress(hInst, "GetFileVersionInfoSizeW");
#else
lpfnGETFILEVERSIONINFOSIZE lpfnGetFileVersionInfoSize = (lpfnGETFILEVERSIONINFOSIZE)GetProcAddress(hInst, "GetFileVersionInfoSizeA");
#endif // UNICODE
dwVer = lpfnGetFileVersionInfoSize(
_T("C:\\Program Files\\Beyond Compare 2\\BC2.exe"),
&dwHandle);
#else
dwVer = GetFileVersionInfoSize(
_T("C:\\Program Files\\Beyond Compare 2\\BC22.exe"),
&dwHandle);
DWORD dwError = GetLastError();
#endif
}
Uncomment _USE_EXPLICITTo compile using explicit link that checks for the OS version and loads appropriate versions of functions depending on UNICODE being defined or not.
JohnCz
|
|
|
|
|
I changed to the non ex version for now, turns out I have a lot of errors to fix in my program to run in XP nice and smooth. I haven't written all the code for the GetFileVersionInfo yet, I have to package the program first, post it on the internet, and then go back and finish the code. Give me a couple of days to experiment with your post, so I can comment on it.
But thanks for the extra help.
|
|
|
|
|
Another thing to check:
Is your project using targetver.h? If yes, change constants to define 0x0500 to target Windows XP.
If not, make sure you define WINVER, _WIN32_WINNT and _WIN32_WINDOWS as 0x500 in stdafx.h before any include.
Compiler will then flag all errors coming from usage of the functions that are not defined in XP.
JohnCz
|
|
|
|
|
Yes, the wizard included it in my stdafx.h, and rc file. So I should do a temp 0x500 to make all the XP errors surface?
I think it was just the 4 functions, when I moved the project to vista to make sure that it worked, and worked all the UAC stuff. Then I moved it back to XP just to make sure all was good, and to build my deployment project.
stdafx.h
#pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
|
|
|
|
That is not guaranteed. It may also depend on SDK version you are using for build.
Compiler will flag errors if header files contain #ifdef with specific versions of windows around some functions to exclude definition for certain versions of Windows.
So, you may have some help in finding out what is excluded for XP but you may still be left with some unknowns to resolve on your own.
JohnCz
|
|
|
|
|