You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 1639 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Sungwoo Park
Version: 3.06
OS: Redhat Linux 6.2
Submission from: gs100.sp.cs.cmu.edu (128.2.205.110)
Hello,
I am trying to create a two dimensional array using alloc() in the C realm,
which I want to pass to the Ocaml realm via a callback function.
I wonder if there is any limit on the memory that alloc() can use.
It seems to me that when alloc() allocates many arrays, an abnormal allocation
occurs: alloc() attempts to use a memory chunk that has already been allocated.
Below is the original code (no need to read it at the moment):
fprintf(stdout, "raw_map.config.x_size = %d\n", raw_map.config.x_size);
fprintf(stdout, "raw_map.config.y_size = %d\n", raw_map.config.y_size);
ocaml_raw_map = alloc(raw_map.config.x_size, 0);
for (x = 0; x < raw_map.config.x_size; x++) {
// floating point numbers take 2 words.
ocaml_raw_map_line = alloc(2 * raw_map.config.y_size, Double_array_tag);
fprintf(stdout, "ocaml_raw_map_line[%d] = %0x\n", x, ocaml_raw_map_line);
for (y = 0; y < raw_map.config.y_size; y++)
Store_double_field(ocaml_raw_map_line, y, (double)(raw_map.map[x][y]));
// (double)(raw_map.complete_map + x * raw_map.config.y_size + y));
Store_field(ocaml_raw_map, x, ocaml_raw_map_line);
}
Basically what it does is to allocate an array of length '2 * y_size'
'x_size' times.
With x_size = 477 and y_size 170, I get some erroneous result.
Here is the output:
The code consumes a total of 477 * 170 * 8 bytes = 648720 bytes < 1 Mbytes.
I wonder if this happens because there is some limit on the number of times
alloc() can allocate memory, or on the total memory that alloc() can use.
I think the latter is not the case as my current workaround is to allocate
a single array holding all the elements in the two dimensional array (thus,
of the same size).
Sungwoo
The text was updated successfully, but these errors were encountered:
I am trying to create a two dimensional array using alloc() in the C realm,
which I want to pass to the Ocaml realm via a callback function.
I wonder if there is any limit on the memory that alloc() can use.
It seems to me that when alloc() allocates many arrays, an abnormal
allocation occurs: alloc() attempts to use a memory chunk that has
already been allocated.
Remember that OCaml has a relocating garbage collector. This means
that it is perfectly possible for a block to be allocated at address
A, then moved to address B, and another block being allocated again at
address A. Nothing abnormal here.
Original bug ID: 1639
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Sungwoo Park
Version: 3.06
OS: Redhat Linux 6.2
Submission from: gs100.sp.cs.cmu.edu (128.2.205.110)
Hello,
I am trying to create a two dimensional array using alloc() in the C realm,
which I want to pass to the Ocaml realm via a callback function.
I wonder if there is any limit on the memory that alloc() can use.
It seems to me that when alloc() allocates many arrays, an abnormal allocation
occurs: alloc() attempts to use a memory chunk that has already been allocated.
Below is the original code (no need to read it at the moment):
fprintf(stdout, "raw_map.config.x_size = %d\n", raw_map.config.x_size);
fprintf(stdout, "raw_map.config.y_size = %d\n", raw_map.config.y_size);
ocaml_raw_map = alloc(raw_map.config.x_size, 0);
for (x = 0; x < raw_map.config.x_size; x++) {
// floating point numbers take 2 words.
ocaml_raw_map_line = alloc(2 * raw_map.config.y_size, Double_array_tag);
fprintf(stdout, "ocaml_raw_map_line[%d] = %0x\n", x, ocaml_raw_map_line);
for (y = 0; y < raw_map.config.y_size; y++)
Store_double_field(ocaml_raw_map_line, y, (double)(raw_map.map[x][y]));
// (double)(raw_map.complete_map + x * raw_map.config.y_size + y));
Store_field(ocaml_raw_map, x, ocaml_raw_map_line);
}
Here is an equivalent code:
fprintf(stdout, "x_size = %d, y_size\n", x_size, y_size);
ocaml_raw_map = alloc(x_size, 0);
for (x = 0; x < x_size; x++) {
ocaml_raw_map_line = alloc(2 * y_size, Double_array_tag);
fprintf(stdout, "ocaml_raw_map_line[%d] = %0x\n", x, ocaml_raw_map_line);
/* ... */
Store_field(ocaml_raw_map, x, ocaml_raw_map_line);
}
Basically what it does is to allocate an array of length '2 * y_size'
'x_size' times.
With x_size = 477 and y_size 170, I get some erroneous result.
Here is the output:
raw_map.config.x_size = 477
raw_map.config.y_size = 170
ocaml_raw_map_line[0] = 4024f30c
ocaml_raw_map_line[1] = 4024edb8
ocaml_raw_map_line[2] = 4024e864
ocaml_raw_map_line[3] = 4024e310
ocaml_raw_map_line[4] = 4024ddbc
ocaml_raw_map_line[5] = 4024d868
ocaml_raw_map_line[6] = 4024d314
ocaml_raw_map_line[7] = 4024cdc0
....
ocaml_raw_map_line[183] = 4024fa84 <- 4024fa84 is used here.
ocaml_raw_map_line[184] = 4024f530 <- 4024f530 is used here.
ocaml_raw_map_line[185] = 4024efdc <- ...
ocaml_raw_map_line[186] = 4024ea88
ocaml_raw_map_line[187] = 4024e534
ocaml_raw_map_line[188] = 4024dfe0
ocaml_raw_map_line[189] = 4024da8c
ocaml_raw_map_line[190] = 4024d538
ocaml_raw_map_line[191] = 4024cfe4
ocaml_raw_map_line[192] = 4024ca90
ocaml_raw_map_line[193] = 4024c53c
ocaml_raw_map_line[194] = 4024bfe8
....
ocaml_raw_map_line[377] = 4024fa84 <- 4024fa84 is used again.
ocaml_raw_map_line[378] = 4024f530 <- 4024f530 is used again.
ocaml_raw_map_line[379] = 4024efdc <- ...
ocaml_raw_map_line[380] = 4024ea88
ocaml_raw_map_line[381] = 4024e534
ocaml_raw_map_line[382] = 4024dfe0
ocaml_raw_map_line[383] = 4024da8c
ocaml_raw_map_line[384] = 4024d538
ocaml_raw_map_line[385] = 4024cfe4
ocaml_raw_map_line[386] = 4024ca90
ocaml_raw_map_line[387] = 4024c53c
ocaml_raw_map_line[388] = 4024bfe8
....
ocaml_raw_map_line[468] = 402b7b5c
ocaml_raw_map_line[469] = 402b7608
ocaml_raw_map_line[470] = 402b70b4
ocaml_raw_map_line[471] = 402b6b60
ocaml_raw_map_line[472] = 402b660c
ocaml_raw_map_line[473] = 402b60b8
ocaml_raw_map_line[474] = 402b5b64
ocaml_raw_map_line[475] = 402b5610
ocaml_raw_map_line[476] = 402b50bc
The code consumes a total of 477 * 170 * 8 bytes = 648720 bytes < 1 Mbytes.
I wonder if this happens because there is some limit on the number of times
alloc() can allocate memory, or on the total memory that alloc() can use.
I think the latter is not the case as my current workaround is to allocate
a single array holding all the elements in the two dimensional array (thus,
of the same size).
The text was updated successfully, but these errors were encountered: