To much memory allocated in _Objects_Extend_information()?

Till Straumann strauman at slac.stanford.edu
Fri Jul 15 18:26:24 UTC 2005


The way I look at it (don't fully understand the code either, just spent 
2 min.)
is that 'maximum' is the maximum number of table entries (not the 
maximum index),
hence allocating 'maximum - minimum_index' would be incorrect.
OTOH, the slots from 0..minimum_index-1 seem to be used as well,
i.e., (further below) they are set to NULL. Therefore, the code seems to
be correct.
(Note that no actual object control blocks (OCB) are allocated. Only the 
information
table is extended, i.e., the tables holding pointers to OCBs.

HTH
-- Till


John Alexandersson wrote:

>Hi all,
>
>I'm sitting here looking at the code in
>score/src/objectextendinformation.c and I don't quite understand how
>the size of the memory to allocate is calculated.
>
>(RTEMS v4.6.2; objectextendinformation.c,v 1.4.2.1 2003/09/04 18:52:47)
>
>Here is an extract of the code which puzzles me:
>
>---8<------------------------------------------------
>
>    /*
>     *  Allocate the tables and break it up.
>     */
>    
>    if ( information->auto_extend ) {
>      object_blocks = (void**)
>        _Workspace_Allocate(
>          block_count *
>             (sizeof(void *) + sizeof(unsigned32) + sizeof(Objects_Name *)) +
>          ((maximum + minimum_index) * sizeof(Objects_Control *))
>          );
>
>      if ( !object_blocks )
>        return;
>    }
>    else {
>      object_blocks = (void**)
>        _Workspace_Allocate_or_fatal_error(
>          block_count * 
>             (sizeof(void *) + sizeof(unsigned32) + sizeof(Objects_Name *)) +
>          ((maximum + minimum_index) * sizeof(Objects_Control *))
>        );
>    }
>
>---8<------------------------------------------------
>
>More precise, it is the last part that I find strange:
>((maximum + minimum_index) * sizeof(Objects_Control *))
>          ^^^^^^^^^^^^^^^
>
>Is it correct behaviour to _add_ minimum_index? Shouldn't it be
>subtracted instead? (maximum - minimum_index)?
> 
>If it, in fact, is the correct behaviour, could some one please
>explain why?
>
>To me it looks like too much memory is allocated here, but since I
>haven't quite got a grip of the overall handling of Objects yet, I
>might very well be wrong.
>
>
>Thanks for enlighten me,
>
>/John Alexandersson - Saab Ericsson Space AB
>
>/"\                              
>\ /    ASCII Ribbon Campaign     
> X   against HTML email & vCards 
>/ \    Keep Email as ASCII       
>
>  
>




More information about the users mailing list