|
Whats the point, writing additional mem free routines to get rid of allocated ones, as it will be deallocated after console is terminated. It is very well designed and quite large but without deallocation.
How can it be OOP one?
9ine
|
|
|
|
|
9ine wrote: Whats the point, writing additional mem free routines to get rid of allocated ones, as it will be deallocated after console is terminated. It is very well designed and quite large but without deallocation.
This makes no sense. Technically, heap memory will be reclaimed by the OS after the program terminates, but if you fail to free it yourself when you are done with it, then your program will slowly (or not so slowly) eat up more and more memory while it is executing (assuming you are allocating based on some set of events -- and if you are not, chances are that data would be better served on the stack anyway). As far as file handles (and pretty much any kernel object), they will NOT be reclaimed when your program exits. This means that if you open a file and then quit, you may need to restart your computer before you can reopen that file (NOT GOOD!).
The point is, if you allocate memory, you should free it. If you don't, do not submit that code as an assignment nor as production code for any company ... it will be rejected as incomplete.
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
|
|
|
|
|
oh, kernel objects memory leaks are my favorite ones! never clean them after myself
whats the point allocation during the start of the console for say 1000 strings of 256 bytes long and then leaving the program without deleting them.
9ine
|
|
|
|
|
9ine wrote: It is very well designed and quite large
It is not well designed if it fails to clean up after itself. True, the operating system will clean up most resources allocated by your program after it exits, even when you don't free them yourself. The problem is, it may not free all of them. There are resources in Windows that are not freed automatically when a program exits. This means that your program could leave behind resource allocations that can never be freed without a restart. Dangling allocations could also cause your application to fail the next time you run it. A resource you allocated previously and did not free is no longer available.
The other problem is that, while your program is running, it continually consumes more and more resources. If you don't free them as soon as you are done using them, they are a waste. Those resources aren't available for use by other applications or the operating system.
Software Zen: delete this;
|
|
|
|
|
I am compiling a project which I have modified to allow it to compile for Linux as well as Windows.
All compiles ok, except in VS6, the compiler keeps complaining about missing header files.
The headers it is looking for are the Linux ones which are ifdef'ed out (it is ignoring the ifdefs )
I have turned off precompiled headers, but this doesn't seem to have made any difference...
This seems to be happening in a different 'stage' to the Compiling/Linking, as the executable is created ok.
any ideas?
Thanks...
Stormblade
|
|
|
|
|
which files is it looking for ?
|
|
|
|
|
General linux specific header files, needed to compile the code under linux.
|
|
|
|
|
Storm-blade wrote: which are ifdef'ed out (it is ignoring the ifdefs )
How are you doing that ? Post some code so that we can check.
|
|
|
|
|
<br />
#ifdef LINUX<br />
<br />
#include <sys/time.h><br />
#include <X11/Xlib.h><br />
#include <X11/Xutil.h><br />
#include <X11/keysym.h><br />
<br />
#else // LINUX<br />
<br />
#endif // LINUX<br />
And LINUX is only defined when compiled under linux...
|
|
|
|
|
Just to make a test: comment these preprocessor definition so you are 100 percent sure they won't interfere and recompile. If this doesn't work, then you probably forgot to put some of the include inside preprocessor definitions. If this works, then you probably declared LINUX somewhere and forgot to remove it.
You can also see which file generates the error, so open the file and check the include part to see if everything is correct.
|
|
|
|
|
|
Try build all or/and delete the old build files. Maybe there is an old version with the headers in it.
If it doesnt help compile every file per hand to get the source of the message.:-X
Greetings from Germany
|
|
|
|
|
KarstenK wrote: Try build all or/and delete the old build files. Maybe there is an old version with the headers in it.
Tried that
KarstenK wrote: If it doesnt help compile every file per hand to get the source of the message.:-X
It doesn't seem to be coming from the compiler itself...
(As I said the code compiles and links correctly).
Something else is reading the source files and looking for just the #include's, and is ignoring #ifdef's etc...
I thought it was the precompiled header stuff... but even without that it still does it.
|
|
|
|
|
CFileDialog will manage it..u don't have to write code for that...
nave
|
|
|
|
|
I see a question here but where is it?
|
|
|
|
|
the OP has deleted it one more selfish guy
|
|
|
|
|
but Im wondering do you know why?because isee a question and i see a answer to Naveen R but when i refresh this page i see only answer Naveen R
|
|
|
|
|
|
i saw it, but why didn't he just updated his post ?
|
|
|
|
|
|
see me wrote: hey toxcct...am not a selfish guy
i didn't see the answer posted by Naveen.
hum, well, even you didn't see it, why have you deleted it, as you reasked it 10 minutes later... moreover, you're on a forum to share, ,not only to get an answer... what's been asked and answered can be found back if someone roam on the forum and search for what or what topic.
edit your posts, but don't delete them when you ask a question.
|
|
|
|
|
toxcct wrote: edit your posts, but don't delete them when you ask a question.
Ok
Dream bigger... Do bigger...Expect smaller
aji
|
|
|
|
|
|
Hello,
I am having troubles with sending data through RS232. I am using the class from Ramon de Klein:
http://www.codeproject.com/system/serial.asp
There I am working with the simple Serial Class (Overlapped).
My problem is that I can only send 16 Byte all together. If I try to send more than 16 Byte, its sending an empty message and I get a NAK from the other side ( I monitored this with a monitoring tool).
This is what the Overlapped structure is set to after sending data:
<br />
Internal 258 unsigned long<br />
InternalHigh 16 unsigned long<br />
Offset 0 unsigned long<br />
OffsetHigh 0 unsigned long<br />
Pointer 0x00000000 void *<br />
hEvent 0x00000780 void *<br />
As you can see, InternalHigh is set to 16. I dont know why. I cant figure out why I am only allowed to send 16 Byte. The dwInQueue as well as the dwOutQueue is big enough to hold more data.
The problem is that I absolutely have no clue where to search for that problem.
Is there anything that restricts the number of bytes to send?
Which codepart can be relevant for you?
This the write method:
<br />
LONG CSerial::Write (const void* pData, size_t iLen, DWORD* pdwWritten, LPOVERLAPPED lpOverlapped, DWORD dwTimeout)<br />
{<br />
CheckRequirements(lpOverlapped,dwTimeout);<br />
<br />
_ASSERTE(!lpOverlapped || pdwWritten);<br />
<br />
m_lLastError = ERROR_SUCCESS;<br />
<br />
DWORD dwWritten;<br />
if (pdwWritten == 0)<br />
{<br />
pdwWritten = &dwWritten;<br />
}<br />
<br />
*pdwWritten = 0;<br />
<br />
if (m_hFile == 0)<br />
{<br />
m_lLastError = ERROR_INVALID_HANDLE;<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Device is not opened\n");<br />
return m_lLastError;<br />
}<br />
<br />
#ifndef SERIAL_NO_OVERLAPPED<br />
<br />
if (!m_hevtOverlapped && (lpOverlapped || (dwTimeout != INFINITE)))<br />
{<br />
m_lLastError = ERROR_INVALID_FUNCTION;<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Overlapped I/O is disabled, specified parameters are illegal.\n");<br />
return m_lLastError;<br />
}<br />
<br />
OVERLAPPED ovInternal;<br />
if (!lpOverlapped && m_hevtOverlapped)<br />
{<br />
memset(&ovInternal,0,sizeof(ovInternal));<br />
ovInternal.hEvent = m_hevtOverlapped;<br />
<br />
lpOverlapped = &ovInternal;<br />
}<br />
<br />
_ASSERTE(!m_hevtOverlapped || HasOverlappedIoCompleted(lpOverlapped));<br />
<br />
char bla[255] = {0x0};<br />
strcpy(bla, (char*)pData);<br />
<br />
if( bla[iLen-1] == 0x03 )<br />
iLen++;<br />
<br />
if (!::WriteFile(m_hFile,pData,iLen,pdwWritten,lpOverlapped))<br />
{<br />
long lLastError = ::GetLastError();<br />
<br />
if (lLastError != ERROR_IO_PENDING)<br />
{<br />
m_lLastError = lLastError;<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Unable to write the data\n");<br />
return m_lLastError;<br />
}<br />
<br />
if (lpOverlapped == &ovInternal)<br />
{<br />
switch (::WaitForSingleObject(lpOverlapped->hEvent,dwTimeout))<br />
{<br />
case WAIT_OBJECT_0:<br />
if (!::GetOverlappedResult(m_hFile,lpOverlapped,pdwWritten,FALSE))<br />
{<br />
m_lLastError = ::GetLastError();<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Overlapped completed without result\n");<br />
return m_lLastError;<br />
}<br />
break;<br />
<br />
case WAIT_TIMEOUT:<br />
CancelCommIo();<br />
<br />
m_lLastError = ERROR_TIMEOUT;<br />
return m_lLastError;<br />
<br />
default:<br />
m_lLastError = ::GetLastError();<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Unable to wait until data has been sent\n");<br />
return m_lLastError;<br />
}<br />
}<br />
}<br />
else<br />
{<br />
if (lpOverlapped)<br />
::SetEvent(lpOverlapped->hEvent);<br />
}<br />
<br />
#else<br />
<br />
if (!::WriteFile(m_hFile,pData,iLen,pdwWritten,0))<br />
{<br />
m_lLastError = ::GetLastError();<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Unable to write the data\n");<br />
return m_lLastError;<br />
}<br />
<br />
#endif<br />
<br />
return m_lLastError;<br />
}<br />
This is how I initialize the com port:
<br />
lLastError = rfi->serial.Open(_T("COM1"),10000,10000,true);<br />
if (lLastError != ERROR_SUCCESS)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to open COM-port"));<br />
<br />
lLastError = rfi->serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);<br />
if (lLastError != ERROR_SUCCESS)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port setting"));<br />
<br />
lLastError = rfi->serial.SetupHandshaking(CSerial::EHandshakeOff);<br />
if (lLastError != ERROR_SUCCESS)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port handshaking"));<br />
<br />
lLastError = rfi->serial.SetMask(CSerial::EEventBreak |<br />
CSerial::EEventCTS |<br />
CSerial::EEventDSR |<br />
CSerial::EEventError |<br />
CSerial::EEventRing |<br />
CSerial::EEventRLSD |<br />
CSerial::EEventRecv);<br />
if (lLastError != ERROR_SUCCESS)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port event mask"));<br />
<br />
lLastError = rfi->serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking);<br />
if (lLastError != ERROR_SUCCESS)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port read timeout."));<br />
<br />
HANDLE hevtOverlapped = ::CreateEvent(0,TRUE,FALSE,0);;<br />
if (hevtOverlapped == 0)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to create manual-reset event for overlapped I/O."));<br />
<br />
OVERLAPPED ov = {0};<br />
ov.hEvent = hevtOverlapped;<br />
<br />
HANDLE hevtStop = ::CreateEvent(0,TRUE,FALSE,_T("Overlapped_Stop_Event"));<br />
if (hevtStop == 0)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to create manual-reset event for stop event."));<br />
I am searching for a solution for some days now, and it would be really really great to get some help, at least getting a starting point where to look at.
DKT
|
|
|
|
|
You can write more than 16 Bytes, I think the setup of the port.
Or the endpoint of the RS232 (the HArdware) is only liking 16 Bytes.
Can you write in 16 Byte loopes? If not there is big trouble.
Greetings from Germany
|
|
|
|
|