×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    9

    Red face Clearing heap and stack while writing to file

    Hi, I'm very new to symbian c++ (I have been using j2me a lot!) and I've been following a lot of tutorials and I'm still confused about when I need to deallocate certain objects. Here is my program. I'm trying to write the WLan mac address to a text file. And it never creates the file because of a Memory Alloc: error.
    Code:
    #ifdef __GCCE__
    #include <staticlibinit_gcce.h>
    #endif
    #include <f32file.h>
    #include <e32std.h>
    #include "main.h"
    
    LOCAL_C void mainL(CConsoleBase* con) {
    
      _LIT(KTxtHello, "Hello.\n");
      _LIT(KTxtError,"Error.\n");
      //con->Printf(KTxtHello);
      TBuf8<20> address;
      RProperty::Get(KPSUidWlan,KPSWlanMacAddress,address);
      TBuf<20> wlanMACAddress;
      for ( TInt i = 0; i < address.Length(); i++ )
          {     
          TUint16 addbyte = address[i];
          wlanMACAddress.AppendFormat(_L("%02X:"), addbyte);
          }
      if  ( wlanMACAddress.Length() ) // remove trailing ':'
          {
          wlanMACAddress.Delete(wlanMACAddress.Length()-1, 1);
          }
      
      HBufC8* hBuf = HBufC8::NewL(20);
      hBuf->Des().Copy(wlanMACAddress);
      TPtr8 myPtr = hBuf->Des();
      
      RFs fs;
      RFile file;
      fs.Connect();
      
      file.Replace(fs,_L("C:\\System\\apps\\Image\\address.txt"),EFileWrite);
      file.Write(myPtr);
        
        // add some more data, if needed
      file.Close();
      fs.Close();
        	
    }
    Please help me determine which objects I need to be pushing/popping/etc.

    Thank you in advance.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,671

    Re: Clearing heap and stack while writing to file

    You have a memory leak (the "hBuf" is not deleted), but that is all. ALLOC panic appears at the end of the execution, your file is probably created.
    Note that c:\system is not shown by the built-in file manager (of the phone or the emulator), use a location under c:\Data if you want to see it.

Similar Threads

  1. The stack and the heap of a thread in a process
    By xhsoldier in forum Symbian
    Replies: 9
    Last Post: 2011-02-15, 13:43
  2. max value of Heap and Stack available ?
    By navjotsingh1979 in forum Symbian
    Replies: 9
    Last Post: 2008-11-13, 13:20
  3. Stack and Heap
    By samcqc in forum Symbian
    Replies: 11
    Last Post: 2008-08-05, 14:45
  4. Symbian 9. Heap size, stack size.
    By Ruger666 in forum Symbian
    Replies: 2
    Last Post: 2007-03-26, 11:30
  5. Help! 6600 stack and heap
    By little_girl in forum Symbian
    Replies: 0
    Last Post: 2004-03-31, 04:34

Posting Permissions

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