File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414int
1515main (int argc , const char * argv [])
1616{
17- BFDEV_DEFINE_ARRAY ( array , NULL , TEST_SIZE );
17+ BFDEV_CLASS ( bfdev_array , array )( NULL , TEST_SIZE );
1818 unsigned int count ;
1919
20- bfdev_array_append (& array , 0 , 0 );
21-
2220 for (count = 0 ; count < TEST_LOOP ; ++ count ) {
2321 unsigned int num ;
2422 void * buff ;
2523
2624 num = rand () % TEST_SIZE ;
27- buff = bfdev_array_push (& array , num );
25+ buff = bfdev_array_push (array , num );
2826 if (!buff )
2927 return 1 ;
3028
3129 memset (buff , 0 , TEST_SIZE * num );
3230 printf ("array bfdev_array_push test: %02u: %u\n" , count , num );
3331 }
3432
35- bfdev_array_release (& array );
36-
3733 return 0 ;
3834}
Original file line number Diff line number Diff line change 1212#include <bfdev/stddef.h>
1313#include <bfdev/string.h>
1414#include <bfdev/allocator.h>
15+ #include <bfdev/guards.h>
1516
1617BFDEV_BEGIN_DECLS
1718
@@ -207,6 +208,32 @@ bfdev_array_reserve(bfdev_array_t *array, unsigned long num);
207208extern void
208209bfdev_array_release (bfdev_array_t * array );
209210
211+ static inline bfdev_array_t *
212+ bfdev_array_create (const bfdev_alloc_t * alloc , bfdev_size_t cells )
213+ {
214+ bfdev_array_t * obj ;
215+
216+ obj = bfdev_malloc (alloc , sizeof (* obj ));
217+ if (bfdev_unlikely (!obj ))
218+ return BFDEV_NULL ;
219+ bfdev_array_init (obj , alloc , cells );
220+
221+ return obj ;
222+ }
223+
224+ static inline void
225+ bfdev_array_destroy (bfdev_array_t * obj )
226+ {
227+ bfdev_array_release (obj );
228+ bfdev_free (obj -> alloc , obj );
229+ }
230+
231+ BFDEV_DEFINE_CLASS (bfdev_array , bfdev_array_t * ,
232+ bfdev_array_create (alloc , cells ),
233+ bfdev_array_destroy (_T ),
234+ const bfdev_alloc_t * alloc , bfdev_size_t cells
235+ )
236+
210237BFDEV_END_DECLS
211238
212239#endif /* _BFDEV_ARRAY_H_ */
You can’t perform that action at this time.
0 commit comments