t-cann/embeddingPython

Intergrate and use Numpy C++ API

Closed this issue · 3 comments

import_arrays()
Include Directory and Compiler Flags required.
Anything that need to be passed to Linker?

malloc and calloc

https://www.guru99.com/difference-between-malloc-and-calloc.html

Malloc Example

#include<stdlib.h>
#include<stdio.h>
int main(){
int *ptr;
ptr = malloc(15 * sizeof(*ptr)); 
    if (ptr != NULL) {
      *(ptr + 5) = 480; 
      printf("Value of the 6th integer is %d",*(ptr + 5));
    }
}

Calloc Example

#include <stdio.h>
#include <stdlib.h>
    int main() {
        int i, * ptr, sum = 0;
        ptr = calloc(10, sizeof(int));
        if (ptr == NULL) {
            printf("Error! memory not allocated.");
            exit(0);
        }
        printf("Building and calculating the sequence sum of the first 10 terms \n");
        for (i = 0; i < 10; ++i) { * (ptr + i) = i;
            sum += * (ptr + i);
        }
        printf("Sum = %d", sum);
        free(ptr);
        return 0;
    }

Python Source Distribution trying to find Modules/xxmodule.c

https://github.com/python/cpython/blob/master/Modules/xxmodule.c