?
Solved

Why can this JNI Exception Access Violation Crash be avoided when some printf are plugged in C code?

Posted on 2006-06-14
13
Medium Priority
?
1,277 Views
Last Modified: 2008-03-10
C DLL connected with Java GUI. It runs well with some debugging printfs to DOS windows are plugged in C code while Exception Access Violation crashes when the debugging printfs are commented off. There are some pointers referred to a large size dynamic memory got from calloc().

Is JNI have some inner limit for dynamic memory referring?
When Crashes, I found the pointer to array in dynamic memory was corrupted unexplainably. When printfs are added back in, the pointers work OK.

Obviously I don't want to release the code with those printfs in the code and debugging outputs hanging over the screen.

Thanks a lot!    
0
Comment
Question by:yuanzhou
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16904927
Better post the code
0
 

Author Comment

by:yuanzhou
ID: 16905003
So many codes and functions interrelated. I guess my description was about the essense of problem. My colleagues also encounterred similar situations and tried to explain it by " printf may change memory and put off memory corruption" but still can't fix it or work around it.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16905034
>>So many codes and functions interrelated.

Are there that many commented-out printf statements?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:yuanzhou
ID: 16905081
Many commented-out statements includes printf. I use VC++ 6.0 to compile the DLL.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1500 total points
ID: 16905156
Personally i'd think there's more likely to be a problem caused by a printf *not* commented out accessing something that *is*
0
 

Author Comment

by:yuanzhou
ID: 16905794
Anything commented off is not being accessed by the remaining codes.  
0
 

Author Comment

by:yuanzhou
ID: 16905923
In JNI, will a JAVA garbage collector corrupt the C pointer to dynamic memory of C DLL?
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 16906558
If commenting out stuff causes it to fail, I'd immediately suspect that you are misusing an automatic variable, most likely a string.
0
 

Author Comment

by:yuanzhou
ID: 16906560
I just found one of the pointer reach beyond its define in the C world and corrupt another pointer though I don't quite understand why inserting printfs can put off the crash. Anyway thank you for the helpful discussion.
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 16906724
That's what I meant by automatic variables - when you have strings being displayed, they take up memory space, but if your pointers point to something that overflows into your printf stuff, it doesn't matter too much. When you remove your printfs, it now points into your instructions, corrupting your program and causing a crash.
0
 

Author Comment

by:yuanzhou
ID: 16906800
You gave me a very sound reasoning. Thank you very much!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16906873
>>but if your pointers point to something that overflows into your printf stuff

How does/can it 'overflow'?
0
 

Author Comment

by:yuanzhou
ID: 16906935
This was a pointer to struct array of dim 300, but the pointer incremented to 20000 to build up a large than expected array, therefore corrupted its neighoring pointer value unless printfs were inserted to keep them isolated, from the understanding I've got now.  
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question