473,413 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Weird memory issue with /clr, no problems without

This is baffling me - I'm coming here in a desperate plea that someone
smarter than myself (which isn't hard) might be able to explain what's
going on.

I've got a native C++ console app that has been working perfectly -
built using VCExpress 2005, VC Redist, platform SDK (include
Windows.h, define WIN32_LEAN_AND_MEAN - am I missing anything?)

I recently found out how to "CLR enable" the app by 1) changing my new-
make file to compile with "/EHac /clr" instead of "/EHsc" and 2)
adding "#using <mscorlib.dll>; using namespace System;" to my code.

If I compile the program with all that C++/CLI stuff there's a weird
bug that shows up at runtime but not if I'm stepping through the
debugger - it's as if the debugger is giving extra time for statements
to complete, but I'm just pulling at straws there. There aren't any
threads in the program, so I'm not running into race conditions or
deadlocks within my own code, the problem looks like it's coming from
the environment.

Here's the behavior:
"run" the code in debugger w/no breakpoints: buggy.
"walk" the code in the debugger line by line: no problems.
"run" the code natively (outside the debugger): buggy.
Re-compile without all the C++/CLI stuff and run outside the debugger:
no problems.

What's going on? Is it a difference between the /EHsc (synchronous)
vs. /EHac (async) exception handling? There aren't any exceptions
being thrown - why would that make a difference?

I'm really stuck with this one - has anyone seen anything like this
before?

With tons of appreciation and thanks,

Mesan
Aug 6 '08 #1
7 1266
"Mesan" <93*****@gmail.comwrote in message
news:c1**********************************@j7g2000p rm.googlegroups.com...
This is baffling me - I'm coming here in a desperate plea that someone
smarter than myself (which isn't hard) might be able to explain what's
going on.

I've got a native C++ console app that has been working perfectly -
built using VCExpress 2005, VC Redist, platform SDK (include
Windows.h, define WIN32_LEAN_AND_MEAN - am I missing anything?)

I recently found out how to "CLR enable" the app by 1) changing my new-
make file to compile with "/EHac /clr" instead of "/EHsc" and 2)
adding "#using <mscorlib.dll>; using namespace System;" to my code.

If I compile the program with all that C++/CLI stuff there's a weird
bug that shows up at runtime but not if I'm stepping through the
debugger - it's as if the debugger is giving extra time for statements
to complete, but I'm just pulling at straws there. There aren't any
threads in the program, so I'm not running into race conditions or
deadlocks within my own code, the problem looks like it's coming from
the environment.

Here's the behavior:
"run" the code in debugger w/no breakpoints: buggy.
"walk" the code in the debugger line by line: no problems.
"run" the code natively (outside the debugger): buggy.
Re-compile without all the C++/CLI stuff and run outside the debugger:
no problems.

What is the buggy behavior?

>
What's going on? Is it a difference between the /EHsc (synchronous)
vs. /EHac (async) exception handling? There aren't any exceptions
being thrown - why would that make a difference?

From the docs:
"/clr implies /EHa, and no other /EH options are allowed with /clr."
Maybe try creating a managed console app with the wizard. Then compare the
compiler/linker settings to the settings in your makefile ...any
differences?

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++
>
I'm really stuck with this one - has anyone seen anything like this
before?

With tons of appreciation and thanks,

Mesan
Aug 6 '08 #2
FWIW - here's the default command lines for a wizard-generated CLR console
project...

Compiler:

/Od /D "WIN32" /D "_DEBUG" /D "_UNICODE" /D "UNICODE"
/FD /EHa /MDd /Yu"stdafx.h" /Fp"Debug\TestCLRConsole.pch"
/Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /Zi /clr
/TP /errorReport:prompt
/FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\Sys tem.dll"
/FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\Sys tem.Data.dll"
/FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\Sys tem.XML.dll"
Linker:

/OUT:"E:\Source_LabCDM\Debug\TestCLRConsole.exe" /INCREMENTAL
/NOLOGO /MANIFEST
/MANIFESTFILE:"Debug\TestCLRConsole.exe.intermediat e.manifest"
/MANIFESTUAC:"level='asInvoker' uiAccess='false'"
/DEBUG /ASSEMBLYDEBUG /PDB:"e:\Source_LabCDM\Debug\TestCLRConsole.pdb"
/DYNAMICBASE /FIXED:No /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT
Mark

--
Mark Salsbery
Microsoft MVP - Visual C++

Aug 6 '08 #3
On Aug 6, 12:06*pm, "Mark Salsbery [MVP]"
<MarkSalsbery[MVP]@newsgroup.nospamwrote:
FWIW - here's the default command lines for a wizard-generated CLR console
project...

Compiler:

/Od /D "WIN32" /D "_DEBUG" /D "_UNICODE" /D "UNICODE"
/FD /EHa /MDd /Yu"stdafx.h" /Fp"Debug\TestCLRConsole.pch"
/Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /Zi /clr
/TP /errorReport:prompt
/FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\Sys tem.dll"
/FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\Sys tem.Data.dll"
/FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\Sys tem.XML.dll"

Linker:

/OUT:"E:\Source_LabCDM\Debug\TestCLRConsole.exe" /INCREMENTAL
/NOLOGO /MANIFEST
/MANIFESTFILE:"Debug\TestCLRConsole.exe.intermediat e.manifest"
/MANIFESTUAC:"level='asInvoker' uiAccess='false'"
/DEBUG /ASSEMBLYDEBUG /PDB:"e:\Source_LabCDM\Debug\TestCLRConsole.pdb"
/DYNAMICBASE /FIXED:No /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++
Wow - I am so thankful to both of you for your responses. I'm in the
process of trying them - no luck yet, but I haven't tried anything yet
either. I just wanted to post back and say thank you.

Wish me luck!

Mesan
Aug 6 '08 #4
"Mesan" <93*****@gmail.comwrote in message
news:23**********************************@j7g2000p rm.googlegroups.com...
On Aug 6, 3:38 pm, Mesan <935m...@gmail.comwrote:

I replaced the atoi() call with System::Convert::ToInt32() and that
seems to have fixed it.
Is that a bad solution? It still seems kind of like voodoo to me, I
wish I had a better handle on exactly what caused the issue.

There's nothing wrong with the fix, but again, there wasn't enough info for
me to determine what was going wrong with your call to atoi().
Mark

--
Mark Salsbery
Microsoft MVP - Visual C++
>
Any ideas?
Aug 7 '08 #5
"Mesan" <93*****@gmail.comwrote in message
news:af**********************************@w39g2000 prb.googlegroups.com...
>
temp_led is defined as LED_LIST_type *

LED_LIST_type is defined as:

typedef struct def_LED {
long trans;
int line;
long acct;
long postdt;
long effdte;
char ref[3];
long amt;
char check[8];
char aslkey[7];
char name[67];
char descr[67];
char code[7];
int mos;
char imp[4];
char userid[4];
long rtrndt;
short
Fcheck,Faslkey,Fname,Fdescr,Fcode,Fmos,Fimp,Frtrnd t,Fuserid;
} LED_type;
typedef struct def_LED_LIST {
LED_type data;
struct def_LED_LIST *prior, *next;
} LED_LIST_type;

When atoi() is called, temp is a char[] with the contents "1".
check_months() is a validation function.
address_of_1 is an int, initialized to 1. The check_months() function
wants a pointer to a counter, but in this case I only want to send a
1, I couldn't say &1, so I used &address_of_1.
The magic +2 gets you to the actual string data. When you send
variable length strings back and forth to a DB2 database, the data
comes with the first two bytes as the length of the string, the
remainder is the string data. It's often used as a struct{} with a
short and a char[], but this company commonly used "(short)variable"
to get the length and "variable+2" to access the string data.

I don't have any other threads in the program, the only thing I can
think of is the MS implementation goo behind the scenes that hooks up
the .Net app domain with this native code.

Does this information give sufficient context to the code?

Excellent - thanks for the details!

I don't see anything that should be a problem.

Uninitialized or invalid variable (pointer!) maybe being used somewhere and
it just happens to work...?

If I think of something I'll let you know!

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++

>
Thanks for not giving up on this - I can't help but feel like my use
of Convert::ToInt32() is just makeup - it looks better, but the
underlying problem is still lurking, waiting to catch me with other C+
+/CLI code when I least expect it.
Aug 7 '08 #6
On Aug 7, 12:52*pm, "Mark Salsbery [MVP]"
<MarkSalsbery[MVP]@newsgroup.nospamwrote:
"Mesan" <935m...@gmail.comwrote in message

news:af**********************************@w39g2000 prb.googlegroups.com...


temp_led is defined as LED_LIST_type *
LED_LIST_type is defined as:
* typedef struct def_LED {
* * * long *trans;
* * * int * line;
* * * long *acct;
* * * long *postdt;
* * * long *effdte;
* * * char ref[3];
* * * long *amt;
* * * char check[8];
* * * char aslkey[7];
* * * char name[67];
* * * char descr[67];
* * * char code[7];
* * * int * mos;
* * * char imp[4];
* * * char userid[4];
* * * long *rtrndt;
* * * short
Fcheck,Faslkey,Fname,Fdescr,Fcode,Fmos,Fimp,Frtrnd t,Fuserid;
* * * } LED_type;
* typedef struct def_LED_LIST {
* * *LED_type data;
* * *struct def_LED_LIST *prior, *next;
* * *} LED_LIST_type;
When atoi() is called, temp is a char[] with the contents "1".
check_months() is a validation function.
address_of_1 is an int, initialized to 1. *The check_months() function
wants a pointer to a counter, but in this case I only want to send a
1, I couldn't say &1, so I used &address_of_1.
The magic +2 gets you to the actual string data. *When you send
variable length strings back and forth to a DB2 database, the data
comes with the first two bytes as the length of the string, the
remainder is the string data. *It's often used as a struct{} with a
short and a char[], but this company commonly used "(short)variable"
to get the length and "variable+2" to access the string data.
I don't have any other threads in the program, the only thing I can
think of is the MS implementation goo behind the scenes that hooks up
the .Net app domain with this native code.
Does this information give sufficient context to the code?

Excellent - thanks for the details!

I don't see anything that should be a problem.

Uninitialized or invalid variable (pointer!) maybe being used somewhere and
it just happens to work...?

If I think of something I'll let you know!

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++


Thanks for not giving up on this - I can't help but feel like my use
of Convert::ToInt32() is just makeup - it looks better, but the
underlying problem is still lurking, waiting to catch me with other C+
+/CLI code when I least expect it.- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
Mark - Any ideas come to mind?

Just curious.
Aug 11 '08 #7
Hi,

Found a good answer yet?

I have a very similar problem, and I found a solution: "/
ASSEMBLYDEBUG" (linker switch)

This enables runtime-tracking and disables JIT optimizations.

I __suspect__ the problem lies somewhere in the JIT optimizations -
but after two days of debugging, I still can't say for sure if that is
the case or not.

All I know is that after flipping all the switches that were different
between "debug" and "release" mode, this is the one that did the
trick. Now I've left everything else in standard "release" settings,
but changed this item. [Granted, with runtime debugging no JIT
optimizations, all the other switches may get washed away anyway.]

Be aware that the .Net Garbage Collector runs in a separate thread.
(supposedly you can turn this off with 'gcConcurrent' -
http://msdn.microsoft.com/en-us/library/yhwwzef8.aspx ). But there's
advantages to letting it run concurrently. Whether enough to justify
disabling JIT optimizations, I don't know; but I have a multi-threaded
program anyway, so it's not immediately relevant to me.

(I'm creating a .Net wrapper for a native C library. I have all of
one variable to initialize, and it only happens in a few places in one
file. There's slim chance of it not getting initialized, especially
after two days of me poring over the 8 places it could be. But it
could still be the _way_ I'm initializing things. Who knows...)

Good luck. And if you've found any other solutions, I'd love to hear
them.
Ciao!
Bibek
Mesan wrote:
Thanks for not giving up on this - I can't help but feel like my use
of Convert::ToInt32() is just makeup - it looks better, but the
underlying problem is still lurking, waiting to catch me with other C+
+/CLI code when I least expect it.- Hide quoted text -

Mark - Any ideas come to mind?

Just curious.
Aug 22 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Greenwich Support | last post by:
Hi All, I have a very weird problem which is occurring with a VB.Net app and PostgreSQL 7.3.1. There is a form that has a standard .Net datagrid on it that contains some data from a table in...
7
by: matvdl | last post by:
I have migrated my asp application to asp.net some time ago - but I am still having some difficulties in understanding the best way to mange some tasks. I currently have a page that loads a aspx...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
8
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
9
by: jeungster | last post by:
Hello, I'm trying to track down a memory issue with a C++ application that I'm working on: In a nutshell, the resident memory usage of my program continues to grow as the program runs. It...
6
by: itsolution | last post by:
Hi folks, Could you shed some light on this issue? my program is running on Freebsd as a daemon. When user sends a request, it forks itself and lets its child process handles the request....
6
by: Lucas Kanebley Tavares | last post by:
Hello all, I have a templatized class which has an attribute as: "T *data", all constructors initialize it to zero, and then allocate memory for the array (and that IS done correctly, I've...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.