Get KERNEL EXE 3 when Read file, why?

Login to reply to this topic.
Fri, 2004-12-03 12:59
Joined: 2004-12-02
Forum posts: 9
this is my code
Code:
.....
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 ];
.....
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?

Bluerose

Fri, 2004-12-03 13:24
Joined: 2004-12-02
Forum posts: 9
Get KERNEL EXE 3 when Read file, why?
i found i will get the error once add this code:

User::LeaveIfError( file.Read( ptr ) );


why?

Bluerose
Fri, 2004-12-03 15:39
Joined: 2004-07-28
Forum posts: 1379
Get KERNEL EXE 3 when Read file, why?
Hmmm

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

Sat, 2004-12-04 02:38
Joined: 2004-12-02
Forum posts: 9
Get KERNEL EXE 3 when Read file, why?
Thank didster。
I think i found the reason。

Code:
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 ] ; //[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]*/
....
But there have another problem,i cann't alloc memory if the size too large,at the moment,the phone may have free memory mor than the size that i want to alloc。what should i do ? The function must return a point to TInt*,if i use HBufC8*,how delete it when return the HBufC8.iBuf ?

Bluerose
  • Login to reply to this topic.