This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

array for realview compiler

I want to use two dimensional array on realview compiler with type A[n][10] where n is an variable of type unsigned char. but it show an error.

Parents
  • Note that my comment was about dynamic memory allocation - that the only situation where two static variables of maximum size doesn't fit, but two dynamic allocations fit, is if one of the dynamic calls is large when the other is small, i.e. the two variables following some form of A*N and (M-B*N).

    For situations where both dynamic allocations are large, then neither dynamic nor static allocation can solve the problem. For situations where both allocations are small, it will be trivial to use static allocations instead.

    For the case when one variable needs to be large when the other is small, I wouldn't try to use a union and definitely not traditional dynamic memory. I would instead use a fixed-size memory block and set a pointer x bytes/elements into the block for the second variable, thereby allowing me to configure the subdivision position depending on runtime information. Since the block has a fixed size, I would be able to compute beforehand if the two variables will fit after each other, instead of having to test a dynamic allocation and check for a NULL pointer. And I wouldn't need the overhead of the dynamic memory allocation/release code. And the code can't suffer from fragmentation.

    A union would be a bit boring, since it would be something like:

    union {
        struct { small_A, large_B; } alt_1;
        struct { medium_A, medium_B; } alt_2;
        struct { large_A, small_B; } alt_3;
        ...
    };
    


    where the code may need a large number of in-between subdivisions, and would then need code to - at run time - gets access to alt_1.small_A, or alt2.medium_A, or alt3.large_A, or ...

Reply
  • Note that my comment was about dynamic memory allocation - that the only situation where two static variables of maximum size doesn't fit, but two dynamic allocations fit, is if one of the dynamic calls is large when the other is small, i.e. the two variables following some form of A*N and (M-B*N).

    For situations where both dynamic allocations are large, then neither dynamic nor static allocation can solve the problem. For situations where both allocations are small, it will be trivial to use static allocations instead.

    For the case when one variable needs to be large when the other is small, I wouldn't try to use a union and definitely not traditional dynamic memory. I would instead use a fixed-size memory block and set a pointer x bytes/elements into the block for the second variable, thereby allowing me to configure the subdivision position depending on runtime information. Since the block has a fixed size, I would be able to compute beforehand if the two variables will fit after each other, instead of having to test a dynamic allocation and check for a NULL pointer. And I wouldn't need the overhead of the dynamic memory allocation/release code. And the code can't suffer from fragmentation.

    A union would be a bit boring, since it would be something like:

    union {
        struct { small_A, large_B; } alt_1;
        struct { medium_A, medium_B; } alt_2;
        struct { large_A, small_B; } alt_3;
        ...
    };
    


    where the code may need a large number of in-between subdivisions, and would then need code to - at run time - gets access to alt_1.small_A, or alt2.medium_A, or alt3.large_A, or ...

Children
No data