Difference between pages "r6.0.0:Lfds600 stack guaranteed push" and "r6.0.0:Lfds600 stack new"

From liblfds.org
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
m (1 revision imported)
 
Line 1: Line 1:
{{DISPLAYTITLE:r6.0.0:lfds600_stack_guaranteed_push}}
{{DISPLAYTITLE:r6.0.0:lfds600_stack_new}}
==Source Files==
==Source Files==
  /liblfds600/src/lfds600_stack/lfds600_stack_push_pop.c
  /liblfds600/src/lfds600_stack/lfds600_stack_new.c
  /liblfds600/inc/liblfds600.h
  /liblfds600/inc/liblfds600.h


==Prototype==
==Prototype==
  int lfds600_stack_guaranteed_push( struct lfds600_stack_state *ss, void *user_data );
  int lfds600_stack_new( struct lfds600_stack_state **ss, lfds600_atom_t number_elements );


==Parameters==
==Parameters==
''struct lfds600_stack_state *ss''
''struct lfds600_stack_state **ss''
: A stack state as allocated by ''[[r6.0.0:lfds600_stack_new|lfds600_stack_new]]''.
: A pointer to a pointer onto which is allocated the state which represents this stack. Set to NULL if stack creation fails.


''void *user_data''
''lfds600_atom_t number_elements''
: A void pointer of user data which will be pushed onto the stack.
: The maximum number of elements which can be present in the stack.  These elements will be allocated when the stack is created.  If not all elements could be allocated (malloc() fails), stack creation fails.


==Return Value==
==Return Value==
The return value is 1 upon successful push, 0 upon failure.  Failure occurs only when ''malloc'' fails.
Returns 1 on success and 0 on failure, with ''*ss'' being set to NULL on failure.


==Notes==
==Notes==
The function ''[[r6.0.0:lfds600_stack_push|lfds600_stack_push]]'' fails only when the stack's freelist is empty.  In this event, ''lfds600_stack_guaranteed_push'' can be called, which allocates a new element and pushes using that new element, thus guaranteeing a push, barring the event of ''malloc'' failure.
This function instantiates a stack.


==See Also==
==See Also==
* [[r6.0.0:lfds600_stack|lfds600_stack]]
* [[r6.0.0:lfds600_stack|lfds600_stack]]
* [[r6.0.0:lfds600_stack_pop|lfds600_stack_pop]]
* [[r6.0.0:lfds600_stack_delete|lfds600_stack_delete]]

Latest revision as of 14:07, 4 January 2015

Source Files

/liblfds600/src/lfds600_stack/lfds600_stack_new.c
/liblfds600/inc/liblfds600.h

Prototype

int lfds600_stack_new( struct lfds600_stack_state **ss, lfds600_atom_t number_elements );

Parameters

struct lfds600_stack_state **ss

A pointer to a pointer onto which is allocated the state which represents this stack. Set to NULL if stack creation fails.

lfds600_atom_t number_elements

The maximum number of elements which can be present in the stack. These elements will be allocated when the stack is created. If not all elements could be allocated (malloc() fails), stack creation fails.

Return Value

Returns 1 on success and 0 on failure, with *ss being set to NULL on failure.

Notes

This function instantiates a stack.

See Also