kernel/eka/common/alloc.cpp
branchRCL_3
changeset 257 3e88ff8f41d5
parent 256 c1f20ce4abcf
equal deleted inserted replaced
256:c1f20ce4abcf 257:3e88ff8f41d5
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // kernel\eka\common\alloc.cpp
    14 // e32\common\alloc.cpp
    15 // 
    15 // 
    16 //
    16 //
    17 
    17 
    18 #include "common.h"
    18 #include "common.h"
    19 #include <e32atomics.h>
    19 #include <e32atomics.h>
       
    20 
    20 
    21 
    21 
    22 
    22 #ifndef __KERNEL_MODE__
    23 #ifndef __KERNEL_MODE__
    23 /**
    24 /**
    24 Opens this heap for shared access.
    25 Opens this heap for shared access.
   277 
   278 
   278 @return The number of cells allocated on the heap.
   279 @return The number of cells allocated on the heap.
   279 */
   280 */
   280 EXPORT_C TInt RAllocator::Count() const
   281 EXPORT_C TInt RAllocator::Count() const
   281 	{
   282 	{
   282 	TInt totalAllocSize; 
   283 	return iCellCount;
   283 	return ((RAllocator*)this)->AllocSize(totalAllocSize);
       
   284 	}
   284 	}
   285 
   285 
   286 
   286 
   287 
   287 
   288 
   288 
   459 	DebugFunction(ESetFail, (TAny*)aType, (TAny*)aRate);
   459 	DebugFunction(ESetFail, (TAny*)aType, (TAny*)aRate);
   460 	}
   460 	}
   461 
   461 
   462 
   462 
   463 /**
   463 /**
   464 Obtains the current heap failure simulation type.
       
   465 
       
   466 After calling __DbgSetAllocFail(), this function may be called to retrieve the
       
   467 value set.  This is useful primarily for test code that doesn't know if a heap
       
   468 has been set to fail and needs to check.
       
   469 
       
   470 @return RAllocator::ENone if heap is not in failure simulation mode;
       
   471 		Otherwise one of the other RAllocator::TAllocFail enumerations
       
   472 */
       
   473 UEXPORT_C RAllocator::TAllocFail RAllocator::__DbgGetAllocFail()
       
   474 	{
       
   475 	return((TAllocFail) DebugFunction(EGetFail));
       
   476 	}
       
   477 
       
   478 
       
   479 /**
       
   480 Simulates a burst of heap allocation failures for this heap.
   464 Simulates a burst of heap allocation failures for this heap.
   481 
   465 
   482 The failure occurs for aBurst allocations attempt via subsequent calls 
   466 The failure occurs for aBurst allocations attempt via subsequent calls 
   483 to new or any of the functions which allocate memory from this heap.
   467 to new or any of the functions which allocate memory from this heap.
   484 
   468 
   530 UEXPORT_C TUint RAllocator::__DbgCheckFailure()
   514 UEXPORT_C TUint RAllocator::__DbgCheckFailure()
   531 	{
   515 	{
   532 	return DebugFunction(ECheckFailure);
   516 	return DebugFunction(ECheckFailure);
   533 	}
   517 	}
   534 
   518 
   535 /**
   519 
   536 Gets the current size of the heap.
       
   537 
       
   538 This is the total number of bytes committed by the host chunk, less the number
       
   539 of bytes used by the heap's metadata (the internal structures used for keeping
       
   540 track of allocated and free memory).
       
   541 
       
   542 Size = (Rounded committed size - size of heap metadata).
       
   543 
       
   544 @return The size of the heap, in bytes.
       
   545 */		
       
   546 UEXPORT_C TInt RAllocator::Size() const	
       
   547 	{
       
   548 	return ((RAllocator*)this)->DebugFunction(EGetSize);
       
   549 	}
       
   550 
       
   551 /**
       
   552 @return The maximum length to which the heap can grow.
       
   553 
       
   554 @publishedAll
       
   555 @released
       
   556 */
       
   557 UEXPORT_C TInt RAllocator::MaxLength() const	
       
   558 	{
       
   559 	return ((RAllocator*)this)->DebugFunction(EGetMaxLength);
       
   560 	}
       
   561 
       
   562 /**
       
   563 Gets a pointer to the start of the heap.
       
   564 
       
   565 Note that this function exists mainly for compatibility reasons.  In a modern
       
   566 heap implementation such as that present in Symbian it is not appropriate to
       
   567 concern oneself with details such as the address of the start of the heap, as
       
   568 it is not as meaningful as it was in older heap implementations.  In fact, the
       
   569 "base" might not even be the base of the heap at all!
       
   570 
       
   571 In other words, you can call this but it's not guaranteed to point to the start
       
   572 of the heap (and in fact it never really was, even in legacy implementations).
       
   573 
       
   574 @return A pointer to the base of the heap.  Maybe.
       
   575 */
       
   576 UEXPORT_C TUint8* RAllocator::Base() const	
       
   577 	{
       
   578 	TUint8* base;
       
   579 	((RAllocator*)this)->DebugFunction(EGetBase, &base);	
       
   580 	return base;
       
   581 	}
       
   582 
       
   583 UEXPORT_C TInt RAllocator::Align(TInt a) const	
       
   584 	{
       
   585 	return ((RAllocator*)this)->DebugFunction(EAlignInteger, (TAny*)a);
       
   586 	}
       
   587 
       
   588 UEXPORT_C TAny* RAllocator::Align(TAny* a) const	
       
   589 	{
       
   590 	TAny* result;
       
   591 	((RAllocator*)this)->DebugFunction(EAlignAddr, a, &result);
       
   592 	return result;
       
   593 	}
       
   594 	
       
   595 UEXPORT_C TInt RAllocator::Extension_(TUint, TAny*& a0, TAny*)
   520 UEXPORT_C TInt RAllocator::Extension_(TUint, TAny*& a0, TAny*)
   596 	{
   521 	{
   597 	a0 = NULL;
   522 	a0 = NULL;
   598 	return KErrExtensionNotSupported;
   523 	return KErrExtensionNotSupported;
   599 	}
   524 	}