|
// m_strUserID is a global variable where i get some value// some userid values
char *charUsrId = m_strUserID.GetBuffer(m_strUserID.GetLength());
char *chDefaultIP = m_strDefaultDomain.GetBuffer(m_strDefaultDomain.GetLength());
i am using like this is it correct ?
venu
|
|
|
|
|
g venu wrote: char *charUsrId = m_strUserID.GetBuffer(m_strUserID.GetLength());
char *chDefaultIP = m_strDefaultDomain.GetBuffer(m_strDefaultDomain.GetLength());
there is no problem using this way,
but make sure you call ReleaseBuffer on CString object, before using it for any other operation.
And ofcourse there is no memory leak.
|
|
|
|
|
|
prasad_som wrote: but make sure you call ReleaseBuffer on CString object, before using it for any other operation.
And ofcourse there is no memory leak.
If you don't call ReleaseBuffer, you will get a memory leak.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: If you don't call ReleaseBuffer, you will get a memory leak.
I agree, I was in assumption ReleaseBuffer is been used after call to GetBuffer. My statement was assumming that
|
|
|
|
|
g venu wrote: char *charUsrId = m_strUserID.GetBuffer(m_strUserID.GetLength());
char *chDefaultIP = m_strDefaultDomain.GetBuffer(m_strDefaultDomain.GetLength());
you have to call associated ReleaseBuffer() api of CString Class
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
AFAIK A memory leak occurs when we don't free a block of memory allocated with the new operator.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
No, not al all if you are actually exiting.
It'll be freed automatically when the program is terminated.
|
|
|
|
|
I want to store current time to a text file. And i want to retrieve that value afterwards and want to compare with the some CTime object. So used CArchieve and failed. Here is my code
<br />
CFile TimeFile;<br />
CTime curTime = CTime::GetCurrentTime();<br />
if(!TimeFile.Open<br />
("TimeFile.txt"<br />
,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite))<br />
{<br />
return;<br />
}<br />
CArchive arTimeFile(&TimeFile, CArchive::store,512);<br />
arTimeFile << curTime;<br />
TimeFile.Close();<br />
I am getting debug error and it shows
void CFile::Write(const void* lpBuf, UINT nCount)<br />
{<br />
ASSERT_VALID(this);<br />
ASSERT(m_hFile != (UINT)hFileNull);<br />
--------<br />
please help me.
KIRAN PINJARLA
|
|
|
|
|
insert line arTimeFile.Flush()after writing data to archive.
your code will be like this,
CFile TimeFile;
CTime curTime = CTime::GetCurrentTime();
if(!TimeFile.Open
("TimeFile.txt"
,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite))
{
return;
}
CArchive arTimeFile(&TimeFile, CArchive::store,512);
arTimeFile << curTime;
arTimeFile.Flush();
TimeFile.Close();
|
|
|
|
|
Thank you prasad. It did work.
Now I need a little more help. I want to read that CTime object from that file and want to compare with another CTime object. I wrote like this
CArchive arTempFile(&TimeFile, CArchive::load);<br />
CTime tempTime;<br />
arTempFile >> tempTime;
</big>
How to do this.
Thank you
KIRAN PINJARLA
|
|
|
|
|
what error its showing ? you need to use flush() this time,too.
I've tested same code here, its not giving any error.
|
|
|
|
|
Prasad. I got it. It is working. It was my fault.I have given a wrong object name.
Thank you somuch for ur help.
GOOD LUCK.
KIRAN PINJARLA
|
|
|
|
|
hi all,
its very basic question but i don't know how to do this in win32,
how to create a binry file .
can i create it with CreateFile.
please let me know.
Thanks and regards
Harshal
|
|
|
|
|
If you are using only win32 (an no MFC), I would suggest that you use FILE (with fopen, fclose, fread, fwrite, ...). To start with it, you can have a look here[^]
If you are using the MFC, then I would suggest that you use the CFile class.
|
|
|
|
|
i am using MFC i tried with CFile::Open
with binary flag but it is not working
so now i will try fopen only because i am not going to
read the data from the file.
i will write and append to it.
|
|
|
|
|
harsha_1234 wrote: with binary flag but it is not working
It should work. If you coul provide more information, maybe we can help. What do you mean by 'it is not working' ? Crash, no file created, compile error, ... Give as much detail as possible.
|
|
|
|
|
|
what do you want to store in it ?
BTW, in C++, prefer STL to C file handling functions (std::fstream )
|
|
|
|
|
CreateFile() do create a binary file.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Hi all,
I neeed to read a total of 1500000 bytes via USB.
I need to create a buffer that would receive these USB databytes.
But if I create a buffer to be of more than 60000 bytes wide , I get "stack overflow error".
How do I receive all the bytes/sample points via USB?
Thanks in advance.
|
|
|
|
|
The problem has probably nothing to do with the USB. Post some relevant code so that we can see what you are doing.
|
|
|
|
|
Yes, I think so too.
well,
I use the USB read function FT_Read to read the USB contents which are continuous data of 1500000 bytes.
I need to read them all and hten plot them.
Hence the buffer that is used to read the USB data has to be big enough to receive and store the 15000000bytes in a temp buffer for other operations.
but if the buffer is declared to be rec_buf[Total_num_bytes_to_read]
if the Total_num_bytes_to_read is declared as 64,000 or more the program fails and stays there was an overflow in the stack.
|
|
|
|
|
By declaring rec_buf as a char[] you are putting it onto the stack, which has a limited size. You need to allocate it using the new operator:
char *rec_buf=new char[Total_num_bytes_to_read]
Don't forget to free the memory when you're done with it:
delete [] rec_buf;
|
|
|
|
|
Hi All,
In my project I want to show some statistical data in the graph format. for example the way we can see the line graph in the MS Excel.
In my project I have the x-Axis and Y-axis values stored in to the two dimentional array. I want to show this statastics on the graph in my dialog based application in VC++ 6.0.
can any body please suggest me any free library or code that I can use for the above purpose.
Thanks in Advance.
Dinesh
-- modified at 3:39 Monday 21st August, 2006
|
|
|
|