C Programming Requests from a Java Programmer

So, I need to translate the C library into pure java so that it looks good, but I'm stuck here.

Can someone explain to me what the next pointer is for?

double *DTimeSigBuf[MAX_TIME_CHANNELS]; 

Good. I know this is a double pointer type called DTimeSigBuf, but what is it in brackets? also MAX_TIME_CHANNELS is defined in the h file as:

  #define MAX_TIME_CHANNELS 2 

then in the code this constant value changes, as well as its indication elsewhere, but I don’t know what it means. it is equivalent to say:

 double *DTimeSigBuf = MAX_TIME_CHANNELS; 

if I remember well that the assembler had something similar, for example: mov [BX], CL is called the indirect addressing mode register, does this have anything to do with this? I know that I can be completely lost! because, as the name says, I am a Java programmer.

And another question, what is the effect of this:

 DTimeSigBuf[chanNum] = (double*)malloc(block_size_samples*sizeof(double)); 

Where is block_size_samples int and chanNum for an iterator variable?

Please, help! I swear I work on the Internet all the time.

Thanks guys:)

+4
source share
6 answers

DTimeSigBuf - an array of pointers for input double . This can be considered as an array of double arrays.

 double *DTimeSigBuf[MAX_TIME_CHANNELS]; 

it could be considered

 double DTimeSigBuf[MAX_TIME_CHANNELS][] 

Line

 DTimeSigBuf[chanNum] = (double*)malloc(block_size_samples*sizeof(double)); 

allocates memory for block_size_samples number of double variables for placement in the array pointed to by DTimeSigBuf[chanNum] .

For instance:

If block_size_samples is 4 and chanNum is 1 , you can think of it this way:

 DTimeSigBuf[1] = new double[4]; 
+3
source

This is an array of pointers to double. MAX_TIME_CHANNELS is the size of the array.

The effect of the operator with malloc is the allocation of a block of memory large enough for two-digit values ​​of block_size_samples; the address of the memory block is then assigned to the chanNum element of the DTimeSigBuf array.

+5
source

Its pointer to an array of type double. MAX_CHANNEL_TIMES is a constant, as well as the size of the array

+3
source

If you have C code:

 #define MAX_TIME_CHANNELS 2 double *DTimeSigBuf[MAX_TIME_CHANNELS]; 

In Java, it looks like this:

 final static int MAX_TIME_CHANNELS = 2; double DTimeSigBuf[][] = new double[MAX_TIME_CHANNELS][]; 

And this is in C:

 DTimeSigBuf[chanNum] = (double*)malloc(block_size_samples*sizeof(double)); 

allocates space for dimension y.

In Java, this is:

 DTimeSigBuf[chanNum] = new double[block_size_samples]; 
+3
source

DTimeSigBuf is an array of pointers to paired.

Selection selects an array of doublings. That is, the returned pointer is a pointer to the first double array in the block_size_samples array.

+2
source

As already mentioned, the first sections declare an array of pointers twice. Since the declaration does not necessarily allocate memory in C, the third line allocates space for the new line of doublings.

Destruction:

 DTimeSigBuf[chanNum] // chanNum is the position in the array = // equals (double*) // memory address to a double malloc( // get some memory from the system block_size_samples*sizeof(double)); // number of samples times memory needed for one double 
+1
source

Source: https://habr.com/ru/post/1402531/


All Articles