I'm running a Java application that uses a native C++ library I've
written. The Java application hits one of the native methods pretty
frequently (about 100 ms or so), and while it usually works fine,
sometimes the program crashes with an error message about the heap.
The method which seems to be causing the problem is very simple, and
does no manual manipulation of the heap. But it does use an iterator.
Could this be the issue?
Other things to note about the error. The "Function=" part references
a function that is NEVER used in my app. The method referenced by the
current Java thread referenced is used, however.
I've renamed the methods below for clarity. Everything else is cut
and pasted from the error output.
Thanks for any help,
cpp
------------------ERROR MESSAGE FOLLOWS---------------------------
The Java method
Unexpected Signal : EXCEPTION_ACCES S_VIOLATION (0xc0000005) occurred
at PC=0x2C9
0A47
Function=Java_M yClass_methodWh ichIsNeverUsedI nMyApp+0xA757
Library=C:\myLi brary.dll
Current Java thread:
at MyClass.methodW hichUsesIterato r(Native Method)
.......
Heap at VM Abort:
Heap
def new generation total 576K, used 350K [0x10010000, 0x100b0000,
0x104f0000)
eden space 512K, 56% used [0x10010000, 0x10057be0, 0x10090000)
from space 64K, 100% used [0x100a0000, 0x100b0000, 0x100b0000)
to space 64K, 0% used [0x10090000, 0x10090000, 0x100a0000)
tenured generation total 1408K, used 36K [0x104f0000, 0x10650000,
0x14010000)
the space 1408K, 2% used [0x104f0000, 0x104f91b0, 0x104f9200,
0x10650000)
compacting perm gen total 4096K, used 1186K [0x14010000, 0x14410000,
0x1801000
0)
the space 4096K, 28% used [0x14010000, 0x14138bf0, 0x14138c00,
0x14410000) 7 1458
On Fri, 27 Aug 2004 07:21:10 GMT, cppaddict <he***@hello.co m> wrote: I'm running a Java application that uses a native C++ library I've written. The Java application hits one of the native methods pretty frequently (about 100 ms or so), and while it usually works fine, sometimes the program crashes with an error message about the heap.
The method which seems to be causing the problem is very simple, and does no manual manipulation of the heap. But it does use an iterator. Could this be the issue?
If you are using the iterator incorrectly, then yes, of course.
Obviously doing anything at all except assigning to an invalidated
iterator causes undefined behaviour.
Tom If you are using the iterator incorrectly, then yes, of course. Obviously doing anything at all except assigning to an invalidated iterator causes undefined behaviour.
Sorry, I should have posted the code. Here it is... it test if the
given set of Point - Color values match those at a given position on
the screen:
bool NativeOcr::test Points(Point positionCoords, std::map<Point,
COLORREF> testPnts) const {
//if one point mismatches, we set it to false and return
bool retVal = true;
std::map<Point, COLORREF>::iter ator iter;
int x,y;
for (iter = testPnts.begin( ); iter != testPnts.end(); ++iter)
{
Point offset = iter->first;
COLORREF testColor = iter->second;
x = positionCoords. getX() + offset.getX();
y = positionCoords. getY() + offset.getY();
if (GetPixel(hDc_, x,y) != testColor) {
retVal = false;
break;
}
}
return retVal;
}
On Fri, 27 Aug 2004 09:47:03 GMT, cppaddict <he***@hello.co m> wrote: If you are using the iterator incorrectly, then yes, of course. Obviously doing anything at all except assigning to an invalidated iterator causes undefined behaviour.
Sorry, I should have posted the code. Here it is... it test if the given set of Point - Color values match those at a given position on the screen:
bool NativeOcr::test Points(Point positionCoords, std::map<Point, COLORREF> testPnts) const {
Did you mean to pass the map by value? Something like this would be
better:
bool NativeOcr::test Points(Point positionCoords, std::map<Point,
COLORREF> const& testPnts) const {
//if one point mismatches, we set it to false and return
bool retVal = true;
std::map<Point, COLORREF>::cons t_iterator iter,
end = testPnts.end();
int x,y;
for (iter = testPnts.begin( ); iter != end; ++iter)
{
Point const& offset = iter->first;
COLORREF testColor = iter->second;
x = positionCoords. getX() + offset.getX();
y = positionCoords. getY() + offset.getY();
if (GetPixel(hDc_, x,y) != testColor) {
retVal = false;
break;
}
}
return retVal;
}
In any case, I couldn't see a bug in the original code, apart from the
noted performance bug. This implies that you must be corrupting the
heap or causing undefined behaviour in another function somewhere.
Tom In any case, I couldn't see a bug in the original code, apart from the noted performance bug. This implies that you must be corrupting the heap or causing undefined behaviour in another function somewhere.
Any idea why the error I posted is saying that there is an access
violation on a function that is NEVER used ANYWHERE in my app. Can
this be caused by heap overflow?
Here's the relevant part of the error message again:
Unexpected Signal : EXCEPTION_ACCES S_VIOLATION (0xc0000005) occurred
at PC=0x2C9
0A47
Function=Java_M yClass_methodWh ichIsNeverUsedI nMyApp+0xA757
Thanks again,
cpp
cppaddict <he***@hello.co m> wrote in message news:<np******* *************** **********@4ax. com>...
[ ... ] bool NativeOcr::test Points(Point positionCoords, std::map<Point, COLORREF> testPnts) const {
//if one point mismatches, we set it to false and return bool retVal = true;
std::map<Point, COLORREF>::iter ator iter; int x,y; for (iter = testPnts.begin( ); iter != testPnts.end(); ++iter) { Point offset = iter->first; COLORREF testColor = iter->second; x = positionCoords. getX() + offset.getX(); y = positionCoords. getY() + offset.getY(); if (GetPixel(hDc_, x,y) != testColor) { retVal = false; break; } }
return retVal; }
I don't see an obvious bug in this code -- I suspect you're looking in
the wrong place. OTOH, I'd personally write the code a bit
differently, something along these lines:
// warning: untested code.
typedef std::pair<Point , COLORREF> mapped;
struct pt_mm : public std::binary_fun ction<Point, mapped, bool> {
bool operator()(Poin t const &pos, mapped const &i) const {
HDC hDc_;
Point offset = i.first;
int x = pos.getX() + offset.getX();
int y = pos.getY() + offset.getY();
return GetPixel(hDc_, x, y) != i.second;
}
};
typedef std::map<Point, COLORREF> ptmap;
bool NativeOcr::test Points(Point const &pos, ptmap const &pts) {
return std::find_if(pt s.begin(), pts.end(),
std::bind1st(pt _mm(), pos)) == pts.end();
}
As a less topical aside, if your call to GetPixel is to the one in
Windows, you might want to check in a Windows programming newsgroup
about how to use a DIBSection instead -- it'll probably be quite a bit
faster.
--
Later,
Jerry.
The universe is a figment of its own imagination. As a less topical aside, if your call to GetPixel is to the one in Windows, you might want to check in a Windows programming newsgroup about how to use a DIBSection instead -- it'll probably be quite a bit faster.
Jerry,
You have a sharp eye. After many hours bug tracking yesterday, I
traced almost all problems in my app (both bugs and speed) to
excessive use of GetPixel. It is:
1. Not thread safe. Having multiple threads access it causes strange
heap and memory exception errors.
2. Slow. I am looking for an alternative now. I'll take a look at
DIBSECTION. I was also thinking of of BitBlt
Let me know if you have any other advice.
Thanks again,
cpp
cppaddict <he***@hello.co m> wrote: I traced almost all problems in my app (both bugs and speed) to excessive use of GetPixel. It is:
1. Not thread safe. Having multiple threads access it causes strange heap and memory exception errors.
You should assume things are not thread-safe, unless there is
specific documentation to the contrary. In particular, any Windows
objects (eg. windows, GDI objects, strings, timers, ...) are most
unlikely to be thread-safe, you should either use mutexes, or only
access them from one thread.
2. Slow. I am looking for an alternative now. I'll take a look at DIBSECTION. I was also thinking of of BitBlt
GetPixel was designed for occasional use.. if you need to scan a
large area you should retrieve that area to memory first and then
work within that memory. IMHO the windows GDI interface is horrible,
I'd suggest you use some other graphics library for manipulating
images and then blit them to the screen when appropriate. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: richard.forrest1 |
last post by:
I have a problem with an abstract interface class whose implementation
classes need to return different iterator types (but with the same
value_types etc).
Classes A and B both conform to the same abstract Interface class. Interface
has a pair of virtual functions begin() and end() that generate a typical
STL style range. Classes A and B provide different implementations, maybe
using different types of container. The problem is that, to...
|
by: deancoo |
last post by:
I have gotten into the habit of often using copy along with an insert
iterator. There are scenarios where I process quite a lot of data this way.
Can someone give me a general feel as to how much of a performance hit I'm
taking using this technique versus using 'copy' to copy directly into a
container with elements in place?
Thanks,
d
|
by: codefixer |
last post by:
Hello,
I am trying to understand if ITERATORS are tied to CONTAINERS.
I know the difference between 5 different or 6(Trivial, on SGI).
But what I fail to understand is how can I declare all 5 kinds of
iterators on say a vector.
OR is it that any iterator declared on Vector is Random Iterator which
has the functionality of all the others.
|
by: Lasse Vågsæther Karlsen |
last post by:
I need to merge several sources of values into one stream of values. All
of the sources are sorted already and I need to retrieve the values from
them all in sorted order.
In other words:
s1 =
s2 =
s3 =
for value in ???(s1, s2, s3):
|
by: ma740988 |
last post by:
typedef std::vector < std::complex < double > > complex_vec_type;
// option1
int main()
{
complex_vec_type cc ( 24000 );
complex_vec_type dd ( &cc, &cc );
}
versus
| |
by: John Salerno |
last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part,
but it does in the second? Is the first statement something different?
False
print 'hi'
hi
Thanks.
|
by: desktop |
last post by:
1)
I have this code:
std::list<intmylist;
mylist.push_back(1);
mylist.push_back(2);
mylist.push_back(3);
mylist.push_back(4);
|
by: Juha Nieminen |
last post by:
Assume we have this:
std::list<Typelist1(10, 1), list2(20, 2);
std::list<Type>::iterator iter = list1.end();
list1.swap(list2);
What happens here, according to the standard?
1) 'iter' still points to list1::end().
2) 'iter' now points to list2::end().
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |