|
So, how to make it safe? Use thread mutex: ?
A& foo()
{
Wait_Mutex(...);
static A a;
Release_Mutex(...);
} ??
This looks very bad performance!
|
|
|
|
|
It depends on what you need. If you wish to have it shared for all threads, you need to work with it like with any other shared memory in multithreading which includes synchronisation (unless only one thread is writing the variable)
rrrado
|
|
|
|
|
Of course, I want to do a shared function by all thread. However, I hope to only have one synchronization in this function. I means, the first thread entered the synchronize, all following thread return the reference of object directly.
|
|
|
|
|
I'm trying to read a char* from a binary file. The data is written to the file correctly, but when I read it back, my string is appended with gibberish. Here's a snippit:
char* load_string(FILE* f)
{
size_t len;
char* str = NULL;
fread(&len, sizeof(size_t), 1, f);
if (len)
{
str=(char*)malloc(len);
fread(str, sizeof(char), len, f);
}
else
{
str=NULL;
}
return str;
}
And here is how I am using the function:
fopen_s(&f, "hi.dat", "rb");
if (f)
{
szLoad = load_string(f);
fclose(f);
}
I'm pretty sure it's a problem with malloc() allocating too much memory, because when I do a strlen(str) it returns as longer than expected, even though len is correctly interpreted from the file.
Any help would be greatly appreciated.
|
|
|
|
|
You need to terminate the string with a null char
malloc the length plus one byte for the '\0'
after you have read the string from the file insert a '\0' at the end of the buffer
|
|
|
|
|
dreamtwister wrote: str=(char*)malloc(len);
fread(str, sizeof(char), len, f);
You might need an extra byte for a NULL otherwise string library functions will just keep going and going and ....
led mike
|
|
|
|
|
i have used following four functions for motion detection part only:
1)AdjustMotionDetectPrecision()
2)SetupMotionDetection()
3)StartMotionDetection()
4)MotionAnalyzer()
using these four functions,motion detected has started.
but i dnt knw how to start recording????
i m sending u some code :
here it is::::
if(frameType > 0)
{
if(frameType == PktSysHeader)
{
memcpy(FileHeader[channelNum], DataBuf, Length);
FileHeaderLen = Length;
}
if(frameType == PktIFrames || frameType ==PktSubIFrames)
{
status = 1;
}
else
{
status = 0;
}
if(frameType == PktMotionDetection)
{
int result[4];
if(bOverlayMode)
{
hkdlg->m_VideoWin.DrawVectEx(channelNum, (char *)DataBuf);
}
else
{
hkdlg->m_bMoving[channelNum] = TRUE;
memcpy(motionData[channelNum],(char*)DataBuf,Length);
}
MotionAnalyzer(ChannelHandle[channelNum],(char*)DataBuf,15,result);
if((result[0] + result[1] + result[2] + result[3]))
{
if (channelNum ==0)
TRACE("!!!!!!!CH=%d motion detect result is %d %d %d %d\n",channelNum,result[0],\
result[1],result[2],result[3]);
//The function Trigger() do the following operation: write the video&audio data which are before the motion frame to file
if(!hkdlg->baftermotion[channelNum])
alarmFile[channelNum].Trigger(gFileHandle[channelNum]);
//when the motion frame returns,clear ualreadywriteframes[channelNum] and set it as 0 ,be ready for writing the video&audio data after motion
hkdlg->ualreadywriteframes[channelNum]=0;
hkdlg->baftermotion[channelNum]=TRUE;
}
return 0;
}
if(frameType == PktOrigImage)
{
return 0;
}
In this code should i start recording after motionanalyser() function?????????????
tyagi
|
|
|
|
|
i am laoding a gif image in picture box. it takes time to load the picture how to avoid this flickering ?. i cant get for gif image
-- modified at 2:00 Tuesday 22nd May, 2007
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
Try SetRedraw(FALSE) before loading and SetRedraw() after the loading.
Try it with "this" and the picturebox.
You can also try to use LockWindowUpdate and UnlockWindowUpdate
I hope it helps
|
|
|
|
|
Hello,
How to import text file and covert to table(new design) in row by row and column by column based on field name.
ashost07
|
|
|
|
|
Hi,
If your text files have the TAB separeted values then opening it with the Excel will get it converted into excel sheet column wise.
Also, you can read the text fiel and use Excel APIs to get the excel sheet created. The main objects Excel.Application, Workbook etc should be used to create a excel sheet.
Manoj
Never Gives up
|
|
|
|
|
Hi,
another option is the ";" format, write the file with ".csv" and import it in Excel saying that he semicolons ";" are like TABS. We use it in that way to have in excell what we want to edit manually from IFix DB
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
this can be helpful
http://www.codeproject.com/useritems/BasicExcel.asp
|
|
|
|
|
I need a source code for a conjunctive normal form, or at least, simplify the process for me. how to transform your sentences to CNF and build a Knowledge base.
--Star
|
|
|
|
|
void main(int argc, char* argv[])
{
}
led mike
|
|
|
|
|
That's what can be given for an URGENT requirment. LOL.
Anything I will say you will bring it down to whatever you want.
|
|
|
|
|
Nice! I've bookmarked that in case I need it in the future
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Oh God!! I forgot the bookmark feature. I actually copy pasted the code to my local disk for future reference!
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
Hi all,
Does anyone know of a very good database class on the net or CP, that one can use to connect to a variety of databases and perform a number of functions???
Can someone please assists me ??
Many Thanks.
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r wrote: Does anyone know of a very good database class on the net or CP
Do you know there are things called "Search Engines"? There is a real good one for the NET called Google and CP has it's own Search engine as well as categorized listings of Articles.
led mike
|
|
|
|
|
Have you ever heard of a thing called "Manners"? Here I'll search it for you:
Wikipedia:
In sociology, manners are the unenforced standards of conduct which show the actor to be cultured, polite, and refined. They are like laws in that they codify or set a standard for human behavior, but they are unlike laws in that there is no formal system for punishing transgressions. They are a kind of norm.
Thus a simple question to make my life a bit easier ... lets just say I thought someone could help.
But thanks for your reply.
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
F*** off
How's that for manners?
led mike
|
|
|
|
|
It's great ....
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Mike, cool down mate. What's wrong with ya. I've never seen you so angry.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
I am, I just didn't feel like spending the time explaining to the twit that good manners would include not asking for help before you make an effort yourself.
led mike
|
|
|
|