×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    21

    How to read large binary file (+/- 5.MB)?

    DearAll,

    I'm newbie in symbian s60, I have to wrap CDRMLicenseChecker class for Qt S60, first i try to implement CDRMLicenseChecker in symbian S60 but I have got runtime error "Memory Full close some application and try again".
    this my symbian code:

    Code:
                                    ...............................................................................  
                                    _LIT(KDRMFileName, "e:\\data\\TEST.DCF");
                                    _LIT(KDRMDecrypted, "e:\\data\\test.mp3");
    
                                    LIT(KExpired, "Lincese expired");
                                  _LIT(KActive, "lincese active");
                                  _LIT(KHasNoRight, "No Right License");
                                  _LIT(KErrorProcess, "KErrorProcess");
                                   _LIT(KErrDRMNotFound, "KErrNotFound");
                                   
                                     RFile file;
    				RFs& fileServera = iCoeEnv->FsSession();
    				User::LeaveIfError(file.Open(fileServera, KDRMFileName, EFileRead));
    				CleanupClosePushL(file);
    				
    				// Get the file size.
    				TInt fileSize;
    				User::LeaveIfError(file.Size(fileSize));
    			        HBufC8* buf16 = HBufC8::NewLC(fileSize);;
    			        buf16->Alloc();
    			        RFs& fileServer = iCoeEnv->FsSession();
    				TInt ret;
    				ret=drmLicense->CheckLicense(KDRMFileName, buf16);
    						
    				if(ret==KErrNone)
    				{
    					WriteDescToFileL(fileServer, KDRMDecrypted, buf16->Des());
    				}
    				else if(ret== KErrNotFound )
    			       {
    																			
    																																		
    					CAknInformationNote* informationNote;
    
    					informationNote = new (ELeave) CAknInformationNote;
    																																								
    				        informationNote-> ExecuteLD(KErrDRMNotFound);
    			       }
    			       else if(ret== CDRMLicenseChecker::ENoRights)
    				{
    							
    																
    						CAknInformationNote* informationNote;
    
    						informationNote = new (ELeave) CAknInformationNote;
    																						
    							informationNote->ExecuteLD(KHasNoRight);
    			      }
    			      else if(ret== CDRMLicenseChecker::ERightsExpired )
    			     {
    							
    																						
    						    CAknInformationNote* informationNote;
    
    						    informationNote = new (ELeave) CAknInformationNote;
    																												
    						   informationNote-> ExecuteLD(KExpired);
    			      }
    						
    			     else
    			    {
    							CAknInformationNote* informationNote;
    							
    					                 informationNote = new (ELeave) CAknInformationNote;
    																																		
    							informationNote-> ExecuteLD(KErrorProcess);
    			    }
    
                                .......................................................................................................................................
    I want to ask how to create buffer in the right way (like using MALOC in C) in symbian S60 to store decrypted binary content, what should i use HBufC/TBufC/RBuf to create buffer and how to do it?
    Whether I need to explicitly write maximum heapsize in *.mmp file.


    Thanks before,

  2. #2
    Nokia Developer Champion
    Join Date
    Jan 2008
    Location
    Bangalore, India
    Posts
    777

    Re: How to read large binary file (+/- 5.MB)?

    HBufC is ok, but meanwhile you can increase the size of heap in .mmp file.
    and don't forget to free the memory.

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: How to read large binary file (+/- 5.MB)?

    An other question could be if you really need to read that entire file into the memory.
    I do not know Qt, but regular Symbian C++ applications have 1 megabyte heap by default. It can be changed using the EPOCHEAPSIZE command in the .mmp file, you could check for similar settings in Qt.

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    21

    Re: How to read large binary file (+/- 5.MB)?

    DearAll,

    I still encounter the same runtime error "Memory Full close some application and try again", before I continue to implement CDRMLicenseChecker class wrapper for Qt S60.
    I created simple symbian project to read binary file with size 512kb, and then write it to destination file. I dont increase the EPOCHEAPSIZE in *.mmp file because the size of file
    is still below from default EPOCHEAPSIZE. I don't know why, even to read file with size of 512kb I still encounter the same runtime error "Memory Full close some application and try again"
    Is there anything wrong with my code or my nokia 5800 xpressmusic. Below is my code to read binary file with size 512kb, and then write it to destination file:

    Code:
                            ............................................................
                            _LIT(KSourceFileName, "c:\\data\\Test.dm");
                            _LIT(KDestFileName,   "c:\\data\\Test.mp3");
    
    			RFs& fileServer = iCoeEnv->FsSession();
    			
    			RFile file;
    			User::LeaveIfError(file.Open(fileServer, KSourceFileName, EFileRead));
    			CleanupClosePushL(file);
    													
    			// Get the file size.
    			TInt fileSize;
    			User::LeaveIfError(file.Size(fileSize));
    												
    			RBuf8 buffer;
    			User::LeaveIfError(buffer.CreateMax(fileSize));
    			CleanupClosePushL(buffer);
    												
    			User::LeaveIfError(file.Read(buffer, fileSize));
    			CleanupStack::PopAndDestroy(&file);
    			
    			// Write the buffer to a file.
    			WriteDescToFileL(fileServer, KDestFileName, buffer);
    			
    			// Delete the buffer.
    			CleanupStack::PopAndDestroy(&buffer);
    
    			....................................................
    
    			void CBinaryFileAppUi::WriteDescToFileL(RFs& aFs, const TDesC& aFileName, const TDesC8& aBuffer)
    			{
    				RFile file;
    				User::LeaveIfError(file.Replace(aFs, aFileName, EFileWrite));
    				CleanupClosePushL(file);
    				User::LeaveIfError(file.Write(aBuffer, aBuffer.Length()));
    				CleanupStack::PopAndDestroy(&file);
    			}
    
    			............................................................
    Thanks,
    Last edited by srf.hidayat; 2011-01-11 at 11:19.

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: How to read large binary file (+/- 5.MB)?

    Depending on what other things your application does, it is not impossible that the other 512k is really used for something. User::Available can report you about free memory. Since fragmentation issues may occur, it also returns size of the biggest available block.

  6. #6
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to read large binary file (+/- 5.MB)?

    EPOCHEAPSIZE defaults to, I believe, 1MB, and likely you'd hit that when trying to manipulate a 1/2MB file. In Qt you increase heap size by coding

    symbian:TARGET.EPOCHEAPSIZE = 0x1000000 0x1000000

    in your .pro file, where the first hex number is the max heap size, and the second hex number is the increment to heap size as it grows. (The above numbers show a max of 16 MB with 1 MB increments -- adjust to your needs.)

  7. #7
    Registered User
    Join Date
    Aug 2009
    Posts
    21

    Re: How to read large binary file (+/- 5.MB)?

    Hi danhicksbyron,

    Thanks for your reply, that's solve my problem.

    Thanks All.

  8. #8
    Registered User
    Join Date
    Feb 2011
    Posts
    6

    Re: How to read large binary file (+/- 5.MB)?

    Quote Originally Posted by danhicksbyron View Post
    EPOCHEAPSIZE defaults to, I believe, 1MB, and likely you'd hit that when trying to manipulate a 1/2MB file. In Qt you increase heap size by coding

    symbian:TARGET.EPOCHEAPSIZE = 0x1000000 0x1000000

    in your .pro file, where the first hex number is the max heap size, and the second hex number is the increment to heap size as it grows. (The above numbers show a max of 16 MB with 1 MB increments -- adjust to your needs.)
    can i know what does it mean in "0x1000000" ? i dun understand why the 2 same number mean 16 MB and 1 MB .

    and is there any limit how much can i set it to ?

  9. #9
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to read large binary file (+/- 5.MB)?

    Do you understand the difference between hex and decimal??

  10. #10
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    286

    Re: How to read large binary file (+/- 5.MB)?

    Quote Originally Posted by dexterq View Post
    can i know what does it mean in "0x1000000" ? i dun understand why the 2 same number mean 16 MB and 1 MB .

    and is there any limit how much can i set it to ?
    Example shows the same value for both minimum and maximum.
    Minimum value of epocheapsize in danhicsbyron's example is 16MB as is the maximum value.

    1000000 hex = 16777216 dec = 16MB
    1MB would be with one power of 16 less = 100000 hex.

    Qt based application defaults to 8MB heap size in and QtWebkit based application defaults to 32MB heap size. Maximum for epocheapsize is 4GB as that is the maximum that 32bit pointer can address.
    Addressing space doesn't mean you get that much RAM, this is limited how much is free in the device.
    -Janne
    http://twitter.com/#!/koshui

Similar Threads

  1. Read Large File in J2ME ?
    By islam.abdo in forum Mobile Java General
    Replies: 2
    Last Post: 2009-06-13, 09:31
  2. Really need help..about canvas to read a large text file
    By thetoppy in forum Mobile Java General
    Replies: 2
    Last Post: 2008-03-07, 12:08
  3. Replies: 3
    Last Post: 2008-03-04, 11:22
  4. how to read the large file which is in vcard format
    By sangeethavijaysekar in forum Symbian
    Replies: 3
    Last Post: 2007-04-11, 11:39
  5. How to read binary large binary file from...
    By gaudeamus1313 in forum Mobile Java General
    Replies: 5
    Last Post: 2007-03-20, 19:17

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •