Read-only archive of the All About Symbian forum (2001–2013) · About this archive

TUint array allocation problem

3 replies · 0 views · Started 15 October 2005

Hi,

I have a class with a member variable
TUint32* iData;

This is allocated in the ConstructL() of the class like so:
iData = new (ELeave) TUint32[<some_large_value>];
(I tested with values upto <some_large_value> = 176 * 208 )

Correct me if I'm wrong, but under low memory conditions, this allocation
should fail and a leave must occur.

However, when I run this through the LowMem tool, the allocation keeps
giving a KERN-EXEC 3 for each step till a step where there is enough memory
to allocate the array.
(it shows 0% test failure if the above allocation is commented out).

How can I solve this problem? (I.e. not get KERN-EXEC 3 for such an
allocation).

Thanks in advance,

Best Regards,
Sameet.


"Sameet" <[email protected]> wrote in message
news:gjtdECByFHA.1008@extapps30...
> Hi,
>
> I have a class with a member variable
> TUint32* iData;
>
> This is allocated in the ConstructL() of the class like so:
> iData = new (ELeave) TUint32[<some_large_value>];
> (I tested with values upto <some_large_value> = 176 * 208 )
>
> Correct me if I'm wrong, but under low memory conditions, this allocation
> should fail and a leave must occur.
>

Yes, but are you sure that leave occurs at that statement and not earlier?
If your class is not derived from CBase, then you should initialize member
variables, like iData to NULL.

I tried the following:

__UHEAP_FAILNEXT(1);
TUint* data = new (ELeave) TUint[ 176 * 208 ];
__UHEAP_RESET;

and leave occurred in new (ELeave) statement.

Hi,

> Yes, but are you sure that leave occurs at that statement and not earlier?

I'm pretty sure the KERN-EXEC 3 occurs in that statement, since, after I
commented the statement out, the crash didn't occur. (I want it to leave and
not crash).


> If your class is not derived from CBase, then you should initialize member
> variables, like iData to NULL.

The class is derived from CBase.

>
> I tried the following:
>
> __UHEAP_FAILNEXT(1);
> TUint* data = new (ELeave) TUint[ 176 * 208 ];
> __UHEAP_RESET;
>
> and leave occurred in new (ELeave) statement.

This problem occurred only when the variable was declared as a member of the
class. I got a normal leave for automatic variables, as in your case, its
just the member variable that seemed to crash.

Best Regards,
Sameet.


"Sameet" <[email protected]> wrote in message
news:iiikyyKyFHA.2212@extapps30...
> Hi,
>[color=green]
>> Yes, but are you sure that leave occurs at that statement and not
>> earlier?

>
> I'm pretty sure the KERN-EXEC 3 occurs in that statement, since, after I
> commented the statement out, the crash didn't occur. (I want it to leave
> and
> not crash).
>[/color]
There are still two possibilities:
a) crash occurs in memory allocation,
b) memory allocation handles OOM properly (i.e. leaves with KErrNoMemory
error code),
but crash occurs in cleanup actions.

You can easily check this by trapping that new (ELeave) statement. Still
crashes in
the same location -> a). If not, then it's b).
[color=green]
>> If your class is not derived from CBase, then you should initialize
>> member
>> variables, like iData to NULL.

>
> The class is derived from CBase.[/color]

Ok, then there should not be initialisation problems.