Get KERNEL EXE 3 when Read file, why?
| Fri, 2004-12-03 12:59 | |
|
this is my code
Code: ..... when i read a file about 80KByte,it works fine;When the file's size is 340KByte, i get the error : KERNEL EXE 3,Why and how to solve it?TFileName name; RFs fs; fs.Connect(); RFile file; CleanupClosePushL( fs ); CleanupClosePushL( file ); User::LeaveIfError( file.Open( fs, name, EFileStream | EFileRead ) ); TInt size; User::LeaveIfError( file.Size( size ) ); TUint8* tbuf; tbuf= new( ELeave )TUint8[ size ] ; TPtr8 ptr( (TUint8*)tbuf, size ); User::LeaveIfError( file.Read( ptr ) ); CleanupStack::PopAndDestroy( 2 ); TInt16* buf ; buf = new( ELeave )TInt16[ DataSize ]; ..... Bluerose |
|






Forum posts: 9
User::LeaveIfError( file.Read( ptr ) );
why?
Bluerose
Forum posts: 1379
Out of intrest, try this (uses HBufC8 rather than new TUint8):
TInt size;
User::LeaveIfError( file.Size( size ) );
HBufC8* tbuf= HBufC8::NewLC(size);
TPtr8 ptr(tBuf->Des());
file.Read( ptr );
CleanupStack::PopAndDestroy(tBuf);
Dont use User::LeaveIfError around the file.Read call because u will get KErrNone (0) returned when you reach the end of the file....... And use HBufC8 - not new TUint...
didster
Forum posts: 9
I think i found the reason。
RFs fs;
fs.Connect();
RFile file;
CleanupClosePushL( fs );
CleanupClosePushL( file );
User::LeaveIfError( file.Open( fs, name, EFileStream | EFileRead ) );
TInt size;
User::LeaveIfError( file.Size( size ) );
TUint8* tbuf;
tbuf= new( ELeave )TUint8[ size ] ; //[color=red]success[/color]
TPtr8 ptr( (TUint8*)tbuf, size );
User::LeaveIfError( file.Read( ptr ) );
CleanupStack::PopAndDestroy( 2 );
TInt16* buf ;
buf = new( ELeave )TInt16[ DataSize ]; /*[color=red]FAILD when alloc 640K,maybe the free memory is too little[/color]*/
....
Bluerose