mallocfreespace.c

Till Straumann strauman at slac.stanford.edu
Thu May 24 18:35:45 UTC 2007


Kate Feng wrote:
> Is it better to return 0 instead of -1 if there is no free space in the
> heap ?
>
>   
AFAIK, a return value of -1 indicates an internal error
(corrupted heap, illegal region id etc.) whereas 0 indicates that no
free space is available.

I'm not sure it's a good idea to mingle these together.
(-1) can tell you that something's really really messed up...

IMHO, EPICS should check for that case and alert the user.

-- T.
> --- mallocfreespace.c.orig Mon Nov 29 17:45:43 2004
> +++ mallocfreespace.c Thu May 24 13:57:24 2007
> @@ -40,5 +40,5 @@
>    if ( !rtems_region_get_free_information( RTEMS_Malloc_Heap,
> &heap_info ) ) {
>      return (size_t) heap_info.Free.largest;
>    }
> -  return (size_t) -1;
> +  return (size_t) 0;
>  }
>
> Returning -1 broke the following code in EPICS :
>
> return (malloc_free_space() > 100000 + contiguousBlockSize);
>
> Perhaps,
> return ( ((int) malloc_free_space() )> 100000 + contiguousBlockSize);
>
> would be fine, but I thought it's better to return 0 if there is no
> free space in the heap.  What do you think ?
>
> Kate
>
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.com
> http://rtems.rtems.org/mailman/listinfo/rtems-users
>   





More information about the users mailing list