pointers - C segfault when assigning value to address in a struct -


i have 2 structs this

typedef struct data {     int datap;     int channelnumber; } data;  typedef struct ringbuffer {     unsigned int *size;     unsigned int *start;     unsigned int *count;     unsigned int *end;     data *elems; } ringbuffer; 

i trying initialize ring buffer struct @ memory location (embedded application) this:

void rbinit(ringbuffer *rb, unsigned int size) {     //put rb appropriate memory locations     rb->size = (unsigned int *) (rb_utils_size + userspace_offset);     rb->start = (unsigned int *) (rb_utils_start + userspace_offset);     rb->count = (unsigned int *) (rb_utils_count + userspace_offset);     rb->end = (unsigned int *) (rb_utils_end + userspace_offset);     rb->elems = (data *) (rb_data + userspace_offset);      //intialize rb parameter/pointer values     data empty;     empty.datap = 0;     empty.channelnumber = 0;      *(rb->size) = size; //segfault here     *(rb->start) = 0;     *(rb->count) = 0;     *(rb->end) = 0;      *(rb->elems) = empty; } 

however, code segfaults (see comment in code). i've checked gdb rb->size indeed pointing location want put and, yes, location available (shared ram on beaglebone pru). rb_utils_size, userspace_offset , likes hex addresses #defined elsewhere.

i quite stoked might problem.

i not familiar beagleboard, in linux cannot access ram process without first getting access kernel. typically use mmap access memory, , call return pointer memory use in application. may help:

how use shared memory linux in c

is there reason you're trying use specific address instead of getting memory malloc?


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -