#define DIG_BLOCK_SIZE 1024 * 1024
unsigned char * sysMem = NULL;if (error){ std::cout << "failed to allocate block buffer" << std::endl; return -1;}DIG_BLOCK_SIZE = 1024 * 1024
block = Array{Cuchar}(DIG_BLOCK_SIZE)
if ccall((:x_MemAlloc,AcqSynth),Cint,(Ptr{Ptr{Void}},Csize_t),pointer(block),DIG_BLOCK_SIZE)==1
error("Failed to allocate block buffer!")
endOn Oct 5, 2016 12:51 PM, "Jérémy Béjanin" <jeremy....@gmail.com> wrote:
>
> Hello,
>
> I am trying to call a DLL function to allocate a page aligned array from julia. Here is a C++ example using that function. Note that the DLL function is wrapped into this uvAPI api, but is otherwise the same except for the name. The DLL function is called x_MemAlloc, while the API function is called X_MemAlloc. The function should return 0 on success, or 1 on failure.
>
> #define DIG_BLOCK_SIZE 1024 * 1024
>
> uvAPI *uv = new uvAPI;
> unsigned char * sysMem = NULL;
> error = uv->X_MemAlloc((void**)&sysMem, DIG_BLOCK_SIZE);
> if (error)
> {
> std::cout << "failed to allocate block buffer" << std::endl;
> return -1;
> }
>
> Here is my julia code:
>
> DIG_BLOCK_SIZE = 1024 * 1024
out = Ref{Ptr{Cuchar}}()
if ccall((:x_MemAlloc,AcqSynth),Cint,(Ptr{Ptr{Cuchar}},Csize_t),out,DIG_BLOCK_SIZE)==1
> error("Failed to allocate block buffer!")
> end
block = pointer_to_array(out[], DIG_BLOCK_SIZE)
# add finalizer
# We now have all the blocks in the blocks array, we need to extract the# 12-bit samples from that array. The data in the blocks is organized in 4# bytes / 32-bit words, and each word contains two 12-bit samples.# Calculate the number of 32-bit words in the blocks arraynumwords = div(numblocks*DIG_BLOCK_SIZE,4)# Initialize array to store the samplesdata = Array{Int32}(2*numwords)for n=1:numwords # Convert next four bytes to 32-bit string s = reverse(bits(blocks[(n-1)*4+1]))*reverse(bits(blocks[(n-1)*4+2]))*reverse(bits(blocks[(n-1)*4+3]))*reverse(bits(blocks[(n-1)*4+4])) # Parse the first 12 bits as the first sample and the 12 bits 4 bits later as the second sample data[(n-1)*2+1] = parse(Int,reverse(s[1:12]),2) data[(n-1)*2+2] = parse(Int,reverse(s[17:28]),2)end