This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem of sizes for memory pools


On Mon, Jun 30, 2003 at 09:59:57AM +0200, Matthieu.GIRARDIN@fr.thalesgroup.com wrote:
> Hi !
> 
> First thanks to Jonathan and Reji for their answers to my previous post.
> 
> Just another two little questions about memory pools.
> 
>  * I must allocate (malloc) enough memory before to use
> cyg_mempool_fix_create() because (the creation of partitions is done in an
> initialisation step in a root thread but) I can't know by advance sizes of
> theses partitions. So I can't use a static definition... is it correct ? is
> it possible ? I work on eCos to do a layer for a application I don't know :
> so I don't know sizes the application will want... Is it clear ? ask me if
> not.

Summary: You don't know at compile time how big the pool is. So you
have to allocate the memory dynamically at run time.

Thats not a problem. 

> * Now, because I must allocate (equivalent to "static char
> mempoolspace[size]"), what's the link between the size in mempoolspace[size]
> and the block size of cyg_mempool_fix_create() ?
> I have as parametres : a nombre of blocks, a fixed size of blocks.
> I think, tell me if I'm right, I must allocate a tab of char with nb_blocks
> * size_block elements.

void cyg_mempool_fix_create( 
    void *base,
    cyg_int32 size,
    cyg_int32 blocksize,
    cyg_handle_t *handle,
    cyg_mempool_fix *fix )

base points to the memory to be used for the pool.
size is the size of the memory to be used for the pool.
blocksize is the size of a block cyg_mempool_fix_alloc() will return
handle is a handle to the new pool just created. You pass this to all other 
   cyg_mempool_fix_* calls.
fix is the structured used by eCos to manage the pool.

> For example : 
> mempoolspace = (void *) malloc (nb_blocks * size_block * sizeof(char))
> or the equivalent I can't use : 
> static char mempoolspace[nb_blocks * size_blocks];


Its not quite as simple as this. eCos has to keep a bitmap of which
blocks have been allocated and which are still free. It needs some
memory for this. It takes this memory from the pool. This means you
pool will have one, maybe two, sometimes three,...., blocks less than
nb_blocks. The exact number depends on the size of the pool and the
blocksize. The number of blocks is approximately

           (size / blocksize) - ((size / blocksize / 8 / blocksize) + 1)

So if you want nb_blocks in your pools, you probably want
to allocate the memory for nb_blocks + x.

   Andrew 

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]