Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Perl XS binding to a struct with an array of chars*

by Marshall (Canon)
on Nov 22, 2022 at 07:28 UTC ( [id://11148297]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    typedef struct
    {
       int count;
       char *str[];
    } Edje_Message_String_Set;
    
  2. or download this
    malloc( sizeof(Edje_Message_String_Set) + (count-1)*sizeof(char *) );
    
  3. or download this
    Newx(message,1,EdjeMessageStringSet);
    Renewc(message,count+2, char*,EdjeMessageStringSet);
    if (message == NULL) 
            croak("Failed to allocate memory in _new function\n");
    
  4. or download this
    void   Newx(void* ptr, int nitems, type)
    void*  safemalloc(size_t size)
    ...
    if (message == NULL) 
            croak("Failed to allocate memory in _new function\n");
    // Of course should have checked this after the Newx().
    
  5. or download this
    EdjeMessageStringSet* m = (EdjeMessageStringSet*) safemalloc( sizeof(E
    +dje_Message_String_Set) + (count-1)*sizeof(char *) );
    if (m == NULL) 
       croak("Failed to allocate memory in _new function\n");
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11148297]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-18 18:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found