|
Unfortunately I am unable to clarify the 'memory overflow' further as this is the only information I was given and the problem was discovered by someone else.
I shall try to get more details if I am unable to resolve the problem using the advice I have received from yourself and Jorgen.
Under normal conditions, everything runs OK and memory allocation is ample.
The problem occurred while the 'someone else' was developing his own code and got into an error condition that caused a continuous stream of data to be sent to my program. I am now attempting to make my code more robust, to take care of the previously unforseen.
Thanks
cgb
|
|
|
|
|
As previously said this looks like a memory handling problem and not like a socket problem.
If you can not reproduce it with a test case, I suggest adding a crash report[^] to your application. In case your program crashs again, it then will write the exact location (instruction pointer and other registers) to a file and you will be able to pinpoint the bug. Hope it helps.
/Moak
|
|
|
|
|
cgb143 wrote: . Can I control data flow, if so how?
Yes. Just don't read the data as soon as it arrives. The effect will be that the operating system will stop acking the TCP packets from the originating klient. Basically, the faster you read, the faster the other side can send.
cgb143 wrote: I could try to fix the 'memory overflow' by increasing the buffer sizes, but I fear this will only delay the crash until the larger buffer overflows. Suggestions welcome
It sounds like you need a better buffering scheme. First of all, you should consider using a dynamic buffer for storing your incoming data. Perhaps a queue of buffers? So whenever a buffer is full, create a new one and append it to the queue, and write the incoming data to that one. When you've "emptied" a buffer (front of queue) by reading all the data in it, remove it from the queue. If your application needs speed, you can always keep a pool of preallocated and unused buffer from which you take buffers whenever you need a new, and into which you put old and used buffers. Your code may also need to expand the pool of unused buffers, should you run out of buffers.
You should also manage the data flow better. A rule of thumb is to not read data at a faster rate then you can process it. That way it will be harder to perform a Denial of Service attack on your application.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
Thanks for the advice, I'll experiment and see what works best.
If I slow down my 'read rate' can this cause a problem to the sender. What I mean is will Windows prevent the sender from .Send()ing data to his socket (by returning an error) or will Windows buffer the data at a lower level.
I think modifying my buffering scheme will prove to be best.
Thanks
cgb
|
|
|
|
|
Yes, the read rate will "trickle back" to the sender. The TCP protocol is designed such that if the receiver stops sending back ack packets at the same rate as data packets are sent to it, the data flow will slow down, or even stall if there's a complete stop.
> I think modifying my buffering scheme will prove to be best.
I really suggest applying both methods (reading and buffering). Especially so if the server will be connected to the Internet. The last thing you want is vulnerability to denial of service attacks, as it may render the entire machine unusable. At the very least, you should have some upper ceiling on your buffers, and just refuse to accept more data than can be buffered.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
Hi everyone:
I need to use dynamic array in my program. I know in C I can use malloc and realloc to do this. I tried this way, and following is the piece of the code
//////////
VERTEX_BUFFER * vertex_list;
if(vertex_list == NULL){
vertex_list = (VERTEX_BUFFER *)malloc(sizeof(VERTEX_BUFFER));
vertex_index++;
}
else
realloc(vertex_list, (sizeof(VERTEX_BUFFER)) * (++vertex_index)); // reallocate memory
//////////
But it gave an error message everytime the program execute the realloc function.
Could somebody give me a solution to dynamic array please??? Or tell me why this doesn't work.
Thanks in advance
Asura
|
|
|
|
|
Ming Luo wrote: if(vertex_list == NULL){ vertex_list = (VERTEX_BUFFER *)malloc(sizeof(VERTEX_BUFFER)); vertex_index++; }
The code you're showing here has an uninitialized pointer (vertex_list). I'm thinking it is initialized properly in your app, and this example is just a sample to highlight your problem. But have you checked to see that you are indeed initializing vertex_list to NULL? If not, it will contain a non-NULL garbage value, which realloc won't like one bit.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
In addition to the uninitialised variable, realloc may (and often does) return a new pointer, if the block of memory moved. If it fails, then it returns 0. A safe way of reallocating would be:
VERTEX_BUFFER *new_buffer = (VERTEX_BUFFER *)realloc(vertex_list, (sizeof(VERTEX_BUFFER)) * (++vertex_index));<br />
if (new_buffer){<br />
vertex_list = new_buffer;<br />
}else{<br />
...<br />
}<br />
Note that because it may shift blocks around in memory, realloc can be a very slow function to call. Usually in this case it's customary to double the size of the allocation each time - it can be proved that over time the amortised cost of realloc tends to O(1) with the doubling approach, though it does mean you allocate a lot of memory. The STL containers (std::vector etc) do this as far as I can tell. Might be worth looking into using an STL container for your code too; it's usually pretty good at this kind of thing.
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
Ah yes, of course you are right. The old realloc() "trap" is best avoided.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
Hello,
How can I schedule a job to be executed when windows starts(like chkdsk or partition magic - console mode apps)? I'm not interested in windows start-up kind.
Thank you,
Andrei CIUBOTARU
|
|
|
|
|
Hi all!
I am having a problem with a using the CFileDialog Save As common dialog. I have set up various filter strings
(i.e. PCFilter = "PCFilter" + " (*.pc)|*.pc|";
LGFilter = "LGFilter" + " (*.lg)|*.lg|";
ALLFilter = "All Files" + " (*.*)|*.*|";
FilterStr = PCFilter + LGFilter + ALLFilter + "|"; )
and everything works fine when my filenames don't contain extra dots (i.e. myfile.pc)
However, the filter string doesn't seem to work if the file name contains extra dots (ie. my.file.pc) The files with the extra dots do not appear in the browser unless I used the All Files filter.
Any ideas? Does using custom file filter types prevent the display of files with dots in the name?
Thanks!
|
|
|
|
|
Crislen wrote: Any ideas?
Your code works fine for me with multi-dot filenames.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Using SQLXML, Bulk Insert XML with IDENTITY Column ...
I have a program that will insert xml data into a table using the SQLXML Bulk Load COM Object. The bulk load is successful when I supply the RecordId in the xml. When I add an IDENTITY column to the table then the bulk load fails with the following error:
[Cannot insert the value NULL into column 'RecordId', table 'Alphanumericdata.dbo.MacgowanTestCust'; column does not allow nulls. INSERT fails.]
From the following article, XML Bulk Load ignores elements and attributes that are not mapped (either because they are not described in the schema, or because they are annotated in the XSD schema with sql:mapped="false"). All unmapped data goes into the overflow column, if such a column is specified by using sql:overflow-field.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqlxml3/htm/bulkload_9w9w.asp
I have attempted using sql:mapped="false" in the schema file and not using it .. both fail with the “nulls not allowed” error.
I have also set the KeepIdentity(true) to my pISQLXMLBulkLoad object.
Below is the table, xml, xsd and code ...
Any comments or answers are appreciated.
Thanks,
Chris
<br />
char progID[] = "SQLXMLBulkLoad.SQLXMLBulkload.3.0";<br />
CLSID clsid;<br />
wchar_t wide[80];<br />
mbstowcs(wide, progID, 80);<br />
CLSIDFromProgID(wide, &clsid);<br />
ISQLXMLBulkLoad* pISQLXMLBulkLoad = NULL;<br />
if(SUCCEEDED(CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_ISQLXMLBulkLoad, (void**)&pISQLXMLBulkLoad)))<br />
{<br />
hResult = pISQLXMLBulkLoad->put_ConnectionString(bstrConnect);<br />
hResult = pISQLXMLBulkLoad->put_ErrorLogFile(bstrXmlErrorLogFile);<br />
hResult = pISQLXMLBulkLoad->put_KeepIdentity((bool)TRUE);<br />
hResult = pISQLXMLBulkLoad->Execute(bstrXmlSchemaFile, vXmlDataFile);<br />
}<br />
<br />
<br />
<ROOT><br />
<Customers><br />
<RecordId>1</RecordId><br />
<CustomerID>1111</CustomerID><br />
<CompanyName>Sean Chai</CompanyName><br />
<City>NY</City><br />
</Customers><br />
<Customers><br />
<RecordId>2</RecordId><br />
<CustomerID>1112</CustomerID><br />
<CompanyName>Tom Johnston</CompanyName><br />
<City>LA</City><br />
</Customers><br />
<Customers><br />
<RecordId>3</RecordId><br />
<CustomerID>1113</CustomerID><br />
<CompanyName>Institute of Art</CompanyName><br />
</Customers><br />
</ROOT><br />
<br />
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"<br />
xmlns:sql="urn:schemas-microsoft-com:mapping-schema"><br />
<br />
<xsd:element name="Customers" sql:relation="MacgowanTestCust" ><br />
<xsd:complexType><br />
<xsd:sequence><br />
<xsd:element name="RecordId" type="xsd:integer" sql:field="RecordId" /><br />
<xsd:element name="CustomerID" type="xsd:integer" sql:field="CustomerID" /><br />
<xsd:element name="CompanyName" type="xsd:string" sql:field="CompanyName" /><br />
<xsd:element name="City" type="xsd:string" sql:field="City" /><br />
</xsd:sequence><br />
</xsd:complexType><br />
</xsd:element><br />
</xsd:schema><br />
<br />
<ROOT><br />
<Customers><br />
<CustomerID>1111</CustomerID><br />
<CompanyName>Sean Chai</CompanyName><br />
<City>NY</City><br />
</Customers><br />
<Customers><br />
<CustomerID>1112</CustomerID><br />
<CompanyName>Tom Johnston</CompanyName><br />
<City>LA</City><br />
</Customers><br />
<Customers><br />
<CustomerID>1113</CustomerID><br />
<CompanyName>Institute of Art</CompanyName><br />
</Customers><br />
</ROOT><br />
<br />
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"<br />
xmlns:sql="urn:schemas-microsoft-com:mapping-schema"><br />
<br />
<xsd:element name="Customers" sql:relation="MacgowanTestCust" ><br />
<xsd:complexType><br />
<xsd:sequence><br />
<xsd:element name="CustomerID" type="xsd:integer" sql:field="CustomerID" /><br />
<xsd:element name="CompanyName" type="xsd:string" sql:field="CompanyName" /><br />
<xsd:element name="City" type="xsd:string" sql:field="City" /><br />
</xsd:sequence><br />
</xsd:complexType><br />
</xsd:element><br />
</xsd:schema><br />
<br />
<br />
CREATE TABLE [MacgowanTestCust] (<br />
[RecordId] [int] IDENTITY (1, 1) NOT NULL ,<br />
[CustomerID] [int] NOT NULL ,<br />
[DataSourceId] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_MacgowanTestCust_DataSourceId] DEFAULT ('OH'),<br />
[CompanyName] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,<br />
[City] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,<br />
PRIMARY KEY CLUSTERED<br />
(<br />
[RecordId]<br />
) ON [PRIMARY]<br />
) ON [PRIMARY]<br />
GO<br />
<br />
<br />
<?xml version="1.0"?><Error><Record><HResult>0x80004005</HResult><SQLState>01000</SQLState><NativeError></NativeError><ErrorState>1</ErrorState><Severity>0</Severity><Source>Microsoft OLE DB Provider for SQL Server</Source><Description><![CDATA[The statement has been terminated.]]></Description></Record><Record><HResult>0x80004005</HResult><SQLState>23000</SQLState><NativeError></NativeError><ErrorState>2</ErrorState><Severity>16</Severity><Source>Microsoft OLE DB Provider for SQL Server</Source><Description><![CDATA[Cannot insert the value NULL into column 'RecordId', table 'Alphanumericdata.dbo.MacgowanTestCust'; column does not allow nulls. INSERT fails.]]></Description></Record></Error><br />
<br />
<br />
<br />
<br />
|
|
|
|
|
The xml again ...
///////////////////////////////////////////////////
// The code
char progID[] = "SQLXMLBulkLoad.SQLXMLBulkload.3.0";
CLSID clsid;
wchar_t wide[80];
mbstowcs(wide, progID, 80);
CLSIDFromProgID(wide, &clsid);
ISQLXMLBulkLoad* pISQLXMLBulkLoad = NULL;
if(SUCCEEDED(CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_ISQLXMLBulkLoad, (void**)&pISQLXMLBulkLoad)))
{
hResult = pISQLXMLBulkLoad->put_ConnectionString(bstrConnect);
hResult = pISQLXMLBulkLoad->put_ErrorLogFile(bstrXmlErrorLogFile);
hResult = pISQLXMLBulkLoad->put_KeepIdentity((bool)TRUE);
hResult = pISQLXMLBulkLoad->Execute(bstrXmlSchemaFile, vXmlDataFile);
}
///////////////////////////////////////////////////
// xml data (successful) RecordId is included
<ROOT>
<Customers>
<RecordId>1</RecordId>
<CustomerID>1111</CustomerID>
<CompanyName>Sean Chai</CompanyName>
<City>NY</City>
</Customers>
<Customers>
<RecordId>2</RecordId>
<CustomerID>1112</CustomerID>
<CompanyName>Tom Johnston</CompanyName>
<City>LA</City>
</Customers>
<Customers>
<RecordId>3</RecordId>
<CustomerID>1113</CustomerID>
<CompanyName>Institute of Art</CompanyName>
</Customers>
</ROOT>
///////////////////////////////////////////////////
// xsd schema file (successful) RecordId is included
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:element name="Customers" sql:relation="MacgowanTestCust" >
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RecordId" type="xsd:integer" sql:field="RecordId" />
<xsd:element name="CustomerID" type="xsd:integer" sql:field="CustomerID" />
<xsd:element name="CompanyName" type="xsd:string" sql:field="CompanyName" />
<xsd:element name="City" type="xsd:string" sql:field="City" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
///////////////////////////////////////////////////
// xml data (fails) attempting to use identity column
<ROOT>
<Customers>
<CustomerID>1111</CustomerID>
<CompanyName>Sean Chai</CompanyName>
<City>NY</City>
</Customers>
<Customers>
<CustomerID>1112</CustomerID>
<CompanyName>Tom Johnston</CompanyName>
<City>LA</City>
</Customers>
<Customers>
<CustomerID>1113</CustomerID>
<CompanyName>Institute of Art</CompanyName>
</Customers>
</ROOT>
///////////////////////////////////////////////////
// xsd schema file (fails) attempting to use identity column
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:element name="Customers" sql:relation="MacgowanTestCust" >
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CustomerID" type="xsd:integer" sql:field="CustomerID" />
<xsd:element name="CompanyName" type="xsd:string" sql:field="CompanyName" />
<xsd:element name="City" type="xsd:string" sql:field="City" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
///////////////////////////////////////////////////
// table
CREATE TABLE [MacgowanTestCust] (
[RecordId] [int] IDENTITY (1, 1) NOT NULL ,
[CustomerID] [int] NOT NULL ,
[DataSourceId] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_MacgowanTestCust_DataSourceId] DEFAULT ('OH'),
[CompanyName] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[City] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
PRIMARY KEY CLUSTERED
(
[RecordId]
) ON [PRIMARY]
) ON [PRIMARY]
GO
///////////////////////////////////////////////////
// error message
<?xml version="1.0"?><Error><Record><HResult>0x80004005</HResult><SQLState>01000</SQLState><NativeError></NativeError><ErrorState>1</ErrorState><Severity>0</Severity><Source>Microsoft OLE DB Provider for SQL Server</Source><Description><![CDATA[The statement has been terminated.]]></Description></Record><Record><HResult>0x80004005</HResult><SQLState>23000</SQLState><NativeError></NativeError><ErrorState>2</ErrorState><Severity>16</Severity><Source>Microsoft OLE DB Provider for SQL Server</Source><Description><![CDATA[Cannot insert the value NULL into column 'RecordId', table 'Alphanumericdata.dbo.MacgowanTestCust'; column does not allow nulls. INSERT fails.]]></Description></Record></Error>
|
|
|
|
|
|
|
My application is simple dialog based application. I derived the OnOk(), OnCancel() functions in CMyDialog class. I wrote nothing in those functions. But after run this application I could not able to close the dialog. Why it is happeneing so. How can I solve this problem? Here my view is not to close the dialog when I pressed the enter button or escape button. How it is possiable in different ways. Please help me in this.
Nice talking to you.
-- modified at 14:00 Wednesday 7th December, 2005
|
|
|
|
|
on your OnClose and on OnOK functions, make sure you add
CDialog::OnClose() or CDialog::OnOK() after anything you do.
If you override them and leave them empty of course they will do nothing
|
|
|
|
|
Yes. Just I removed the OnCancel derivation. I feel my program as I expected. May be some other solutions too to handle the OnOk and OnCancel also. I think some PreTranslateMessage function is useful. I dont know exactly about this. If any let me know than I am very thankful to him.
Nice talking to you.
|
|
|
|
|
G Haranadh wrote: May be some other solutions too to handle the OnOk and OnCancel also.
What is it that you are wanting to handle?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
My intension is I would like to handle Escape button and Enter key in different ways.
Thanks for giving reply
Nice talking to you.
|
|
|
|
|
G Haranadh wrote: My application is simple dialog based application. I derived the OnOk(), OnCancel() functions in CMyDialog class. I wrote nothing in those functions. But after run this application I could not able to close the dialog. Why it is happeneing so. How can I solve this problem? Here my view is not to close the dialog when I pressed the enter button or escape button. How it is possiable in different ways. Please help me in this.
See :
Dialog windows and WM_CLOSE[^]
|
|
|
|
|
Thank you for helping us through codeproject. Thanks alot. Have a nice day I am very glad to talk to you
Nice talking to you.
|
|
|
|
|
Hi,
When I used Visual Studio 6, life was easy, I would edit the main application icon and when I created a desktop shortcut for it, there is was. The same for the 16X16 icon, when I created it, you could see it in the windows explorer.
However, when working with Visual studio .NET 2003, my Application's Icon will not change and stays the default MFC icon.
Any help will be great.
shay
|
|
|
|
|
in fact, a .ico file contains several icons, varying from the size and/or the number of colors.
when you edit an icon with the icon editor within Visual Studio, you should verify that all the devices (that's how they're called) are like you want...
(search the menus for that ; i don't remember exactly where).
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20] | soon : [VisualCalc 3.0]
|
|
|
|