Difference between pages "r6:Function:stack guaranteed push" and "r6:Function: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:
==Source Files==
==Source Files==
  /src/stack/stack_push_pop.c
  /src/stack/stack_new.c
  /inc/liblfds.h
  /inc/liblfds.h


==Prototype==
==Prototype==
  int stack_guaranteed_push( struct stack_state *ss, void *user_data );
  int stack_new( struct stack_state **ss, atom_t number_elements );


==Parameters==
==Parameters==
''struct stack_state *ss''
''struct stack_state **ss''
: A stack state as allocated by ''[[r6:Function:stack_new|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''
''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:Function:stack_push|stack_push]]'' fails only when the stack's freelist is empty.  In this event, ''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:API:Stack|Stack]]
* [[r6:API:Stack|Stack]]
* [[r6:Function:stack_pop|stack_pop]]
* [[r6:Function:stack_delete|stack_delete]]

Latest revision as of 14:07, 4 January 2015

Source Files

/src/stack/stack_new.c
/inc/liblfds.h

Prototype

int stack_new( struct stack_state **ss, atom_t number_elements );

Parameters

struct 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.

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