To much memory allocated in _Objects_Extend_information()?

John Alexandersson john.alexandersson at space.se
Fri Jul 15 11:27:41 UTC 2005


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