# Ccall julia ReadOnlyMemoryError()

**URL:** <https://discourse.julialang.org/t/ccall-julia-readonlymemoryerror/43765>\
**Category:** General Usage\
**Tags:** question, ccall, memory, memory-allocation\
**Created:** [July 27, 2020, 3:23pm UTC](https://discourse.julialang.org/t/ccall-julia-readonlymemoryerror/43765 "2020-07-27T15:23:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashwin\_Sundarka](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwin_sundarka/32/14552_2.png) [@Ashwin\_Sundarka](https://discourse.julialang.org/u/Ashwin_Sundarka)\
**Post date:** [July 27, 2020, 3:23pm UTC](https://discourse.julialang.org/t/ccall-julia-readonlymemoryerror/43765/1 "2020-07-27T15:23:49Z")

</div>

Hii!  
I am calling a C function from Julia using **ccall**. When I am running using a small data size it works perfectly but when I am using a huge data size it gives error **ReadOnlyMemoryError()**

I tried to show a demo of my problem with a easier code below,

Here is a sample of my code,

> In C:

```julia
struct valueType1 {
    Int32 val1[60];
    Int32 val2[60];
};
struct valueType2 {
    Int32 val11[60000];
    Int32 val22[60000];
};
struct valueType1 my_test1(Int32 num_numbers, Int32 *numbers)
{
    struct valueType1 myt;
    int i;
    for(i=0; i < num_numbers; i++){
        myt.val1[i] = numbers[i];
        myt.val2[i] = numbers[i]; 
    }
    return myt;
}

struct valueType2 my_test2(Int32 num_numbers, Int32 *numbers)
{
    struct valueType2 myt;
    int i;
    for(i=0; i < num_numbers; i++){
        myt.val11[i] = numbers[i];
        myt.val22[i] = numbers[i]; 
    }
    return myt;
}

```

The code is compiled to a **dll** file names, **testC.dll**

> In Julia:

```julia
struct type1
      val1::NTuple{60,Int32}
      val2::NTuple{60,Int32}
end

struct type2
      sum11::NTuple{60000,Int32}
      sum22::NTuple{60000,Int32}
end

num_numbers= Int16(60)
number = ones(Int16, (60,1))*Int16(300)

x1=ccall((:my_test1,"testC.dll"),type1,(Int, Ptr{Int16}), num_numbers, pointer(number))

num_numbers2= Int32(60000)
number2 = ones(Int32, (60000,1))*Int16(300)

x2=ccall((:my_test2,"testC.dll"),type2,(Int, Ptr{Int16}), num_numbers2, pointer(number2))

```

when I am using **my\_test1** , I get my result as it should. But with **my\_test2** I get the  
**ReadOnlyMemoryError()**

Anyone have went through similar problem before? Or have any idea how to solve it.

Thanks!
