Exception "Access Violation" in calling new()

Sönke Ludwig ludwig_no at spam_informatik.uni-luebeck.de
Sun May 25 01:42:17 PDT 2008


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.



More information about the Digitalmars-d mailing list