www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Exception "Access Violation" in calling new()

reply Huang Guan <love203a yahoo.com.cn> writes:
I wonder whether I am not familiar with IIRC. It has brought me many troubles
while I was writing my web server.

Of course, muti-threading is used in my server program. In my code, there are a
lot of dynamic memory allocations and I am used to using delete function to
free the allocated memory. Meanwhile, a big problem occurred to me recently and
I got fully lost. Below is the code:


		ByteBuffer encrypted;
		try{
			encrypted = new ByteBuffer( buf.length );
		}catch(Exception e){
			dprint("Exception in new ByteBuffer()");
			throw e;
		}

In my computer, the code above works well all the time. Then I copied to
another computer to run the code. Firstly the exception did not happened. But
when my server program worked for a while, it happened. I knew the string value
of e.msg is "Access violation" from the console. I didn't know why. I have met
the same program a month ago when I was writing another program but soon it
disappeared mysteriously.

Is there anyone who can give me an answer to this problem?
May 25 2008
next sibling parent =?ISO-8859-15?Q?S=F6nke_Ludwig?= writes:
Huang Guan schrieb:
 I wonder whether I am not familiar with IIRC. It has brought me many troubles
while I was writing my web server.
 
 Of course, muti-threading is used in my server program. In my code, there are
a lot of dynamic memory allocations and I am used to using delete function to
free the allocated memory. Meanwhile, a big problem occurred to me recently and
I got fully lost. Below is the code:
 
 
 		ByteBuffer encrypted;
 		try{
 			encrypted = new ByteBuffer( buf.length );
 		}catch(Exception e){
 			dprint("Exception in new ByteBuffer()");
 			throw e;
 		}
 
 In my computer, the code above works well all the time. Then I copied to
another computer to run the code. Firstly the exception did not happened. But
when my server program worked for a while, it happened. I knew the string value
of e.msg is "Access violation" from the console. I didn't know why. I have met
the same program a month ago when I was writing another program but soon it
disappeared mysteriously.
 
 Is there anyone who can give me an answer to this problem?
 
 
I had a similar problem (probably the same). The access violations occured in a file loader thread at "data = new byte[size];" (with multiple others running in parallel). The workaround I'm using now is to disable the GC around the call to new. Unfortunately I could not reproduce the error in a small testcase so I didn't write a bug report.
May 25 2008
prev sibling next sibling parent "Unknown W. Brackets" <unknown simplemachines.org> writes:
What is ByteBuffer?  A class or struct?  Does this ever happen in any of 
your other code, or just there?  Does this ever happen when new'ing 
built-in types?

For example, it could be some operation that ByteBuffer is doing in its 
constructor.  Maybe buf.length is 0 or extremely large, or something. 
Are you using contracts?  Are they compiled in?

Also - note that access violations are exceptions, but segfaults (same 
thing on Linux) are not.

-[Unknown]


Huang Guan wrote:
 I wonder whether I am not familiar with IIRC. It has brought me many troubles
while I was writing my web server.
 
 Of course, muti-threading is used in my server program. In my code, there are
a lot of dynamic memory allocations and I am used to using delete function to
free the allocated memory. Meanwhile, a big problem occurred to me recently and
I got fully lost. Below is the code:
 
 
 		ByteBuffer encrypted;
 		try{
 			encrypted = new ByteBuffer( buf.length );
 		}catch(Exception e){
 			dprint("Exception in new ByteBuffer()");
 			throw e;
 		}
 
 In my computer, the code above works well all the time. Then I copied to
another computer to run the code. Firstly the exception did not happened. But
when my server program worked for a while, it happened. I knew the string value
of e.msg is "Access violation" from the console. I didn't know why. I have met
the same program a month ago when I was writing another program but soon it
disappeared mysteriously.
 
 Is there anyone who can give me an answer to this problem?
 
 
May 25 2008
prev sibling parent reply downs <default_357-line yahoo.de> writes:
Huang Guan wrote:
 I wonder whether I am not familiar with IIRC. It has brought me many troubles
while I was writing my web server.
 
 Of course, muti-threading is used in my server program. In my code, there are
a lot of dynamic memory allocations and I am used to using delete function to
free the allocated memory. Meanwhile, a big problem occurred to me recently and
I got fully lost. Below is the code:
 
 
 		ByteBuffer encrypted;
 		try{
 			encrypted = new ByteBuffer( buf.length );
 		}catch(Exception e){
 			dprint("Exception in new ByteBuffer()");
 			throw e;
 		}
 
 In my computer, the code above works well all the time. Then I copied to
another computer to run the code. Firstly the exception did not happened. But
when my server program worked for a while, it happened. I knew the string value
of e.msg is "Access violation" from the console. I didn't know why. I have met
the same program a month ago when I was writing another program but soon it
disappeared mysteriously.
 
This is why we want traced exceptions. --downs
May 25 2008
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"downs" <default_357-line yahoo.de> wrote in message 
news:g1c244$2ign$1 digitalmars.com...
 Huang Guan wrote:
 I wonder whether I am not familiar with IIRC. It has brought me many 
 troubles while I was writing my web server.

 Of course, muti-threading is used in my server program. In my code, there 
 are a lot of dynamic memory allocations and I am used to using delete 
 function to free the allocated memory. Meanwhile, a big problem occurred 
 to me recently and I got fully lost. Below is the code:


 ByteBuffer encrypted;
 try{
 encrypted = new ByteBuffer( buf.length );
 }catch(Exception e){
 dprint("Exception in new ByteBuffer()");
 throw e;
 }

 In my computer, the code above works well all the time. Then I copied to 
 another computer to run the code. Firstly the exception did not happened. 
 But when my server program worked for a while, it happened. I knew the 
 string value of e.msg is "Access violation" from the console. I didn't 
 know why. I have met the same program a month ago when I was writing 
 another program but soon it disappeared mysteriously.
This is why we want traced exceptions.
I'll reply for Walter: just open it in a debugger and set it to break on access violations! :P
May 25 2008
parent reply BCS <ao pathlink.com> writes:
Reply to Jarrett,

 "downs" <default_357-line yahoo.de> wrote in message
 news:g1c244$2ign$1 digitalmars.com...
 
 This is why we want traced exceptions.
 
I'll reply for Walter: just open it in a debugger and set it to break on access violations! :P
and I'll reply for whoever "Run a server app in a debugger?!?"
May 25 2008
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"BCS" <ao pathlink.com> wrote in message 
news:55391cb32d6e88ca8c626d2f304e news.digitalmars.com...
 Reply to Jarrett,

 "downs" <default_357-line yahoo.de> wrote in message
 news:g1c244$2ign$1 digitalmars.com...

 This is why we want traced exceptions.
I'll reply for Walter: just open it in a debugger and set it to break on access violations! :P
and I'll reply for whoever "Run a server app in a debugger?!?"
And I'll reply for Walter: --oh wait, Walter wouldn't reply. Nevermind.
May 25 2008
prev sibling parent Robert Fraser <fraserofthenight gmail.com> writes:
(sorry about the web interface)

I know of two backtrace hacks out there.... 
- team0xf's (whch requires a runtime replacement)
- Flectioned (which requires debug info on Windows, and doesn't play with DDBG,
but is easier & less invasive)

BCS Wrote:

 Reply to Jarrett,
 
 "downs" <default_357-line yahoo.de> wrote in message
 news:g1c244$2ign$1 digitalmars.com...
 
 This is why we want traced exceptions.
 
I'll reply for Walter: just open it in a debugger and set it to break on access violations! :P
and I'll reply for whoever "Run a server app in a debugger?!?"
May 25 2008