allocation

CUDA - Copy device data to host?

混江龙づ霸主 提交于 2019-12-11 08:43:23
问题 I have device variable and in this variable, I allocate and fill an array in the device, but I have a problem to get data to host. cudaMemcpy() return cudaErrorInvalidValue error. how can I do it? PS: The Code is just example, I know, that In this particular case I can use cudaMalloc because I know the size of the array, but In my REAL code, It computes the size of the array in the device and it needs immediately allocate memory. PS2: I found a similar problem, but I still don't know, how can

Dynamically allocate 2D array without using any loops?

末鹿安然 提交于 2019-12-11 08:42:41
问题 Can we dynamically allocate 2D array without using any for loop or while loops? i there any direct command or function in c c++? 回答1: Without using a loop you will have one restriction in ISO c++ i.e. size of one dimension has to be determined at compile time. Then this allocation can be done in a single statement as follows: #define COLUMN_SIZE 10 // this has to be determined at compile time int main() { int (* arr)[COLUMN_SIZE]; int rows = 20; // this is dynamic and can be input from user

matrices vs. arrays of arrays in C++ and their dynamic allocation

不打扰是莪最后的温柔 提交于 2019-12-11 07:38:35
问题 There is something I still don't quite understand about the way matrices and other multidimensional arrays are represented in C and C+ and how to allocate them dynamically. Consider the following code segment: int main() { int n; cin >> n; int a[n][n]; ... } If I understand correctly, this allocates an n by n matrix of integers on the stack. The (i,j)-th element of the matrix can be accessed using a[i][j]. The compiler automatically converts this into an access into the (n*i+j)-th element of

Java Fill preallocated File with Data (on drive)

£可爱£侵袭症+ 提交于 2019-12-11 07:04:18
问题 i want to download a videofile from the web. It is 121 MB. Now i want to pre allocate this 121 MB on the disk (with zeros or what ever) and fill it step by step with the data of the inputstream from the urlconnection. Or with other words: It doesn't matter how much has been downloaded yet - the file size is always the destinated 121MB. Is it possible? thank you 回答1: i got the solution. First of all i write the empty dummy file and then i reopen the empty file and replace the bytes: System.out

How to dynamically allocate a matrix in C?

社会主义新天地 提交于 2019-12-11 06:43:29
问题 I have to do this exercise: Do an application in C that manages a matrix of integer named "M" and a list of integer named "L". M is a square matrix [nxn] with n chosen by user dynamically. Then do this function: Serialize: given the "M" matrix it return the list L with n^2 elements. The elements of the list are the element of M ordered by row from the first to the second. The second function: Deserialize: given the list L with n^2 elements, it return a matrix [nxn] with elements of L ordered

How can I dynamically allocate 2D-array in one allocate C

妖精的绣舞 提交于 2019-12-11 04:26:43
问题 Can you help me figure out how to allocate a 2D-array in one allocate call? I tried to do: int** arr = (int**)malloc(num * num * sizeof(int*)); But its doesn't work. num is the rows and columns. 回答1: How can i to allocate dynamically array2D in 1 allocate C Let us start with what is a 2D array: Example of a 2D array or "array 3 of array 4 of int" int arr1[3][4]; arr1[0][0] = this; OP's code declares a pointer to pointer to int, not a 2D array nor a pointer to a 2D array. BTW, the cast in not

Polymorphism allocation in a SELECT TYPE construct

和自甴很熟 提交于 2019-12-11 03:02:50
问题 I am trying to define a subroutine which allocates different types of arrays. Here is a simplified version of the code: subroutine Allocation1(Vec) class(*), allocatable, intent(out) :: Vec(:) select type(Vec) type is(real(8)) allocate(Vec(10)); Vec = 0.D0 type is(complex(8)) allocate(Vec(10)); Vec = (0.D0,0.D0) type is(integer) allocate(Vec(10)); Vec = 0 endselect endsubroutine Allocation1 But I got three error messages that I don't understand: error #8306: Associate name defined in

Allocate Pointer and pointee at once

穿精又带淫゛_ 提交于 2019-12-11 02:34:48
问题 If I want to reduce malloc() s (espacially if the data is small and allocated often) I would like to allocate the pointer and pointee at once. If you assume something like the following: struct entry { size_t buf_len; char *buf; int something; }; I would like to allocate memory in the following way (don't care about error checking here): size_t buf_len = 4; // size of the buffer struct entry *e = NULL; e = malloc( sizeof(*e) + buf_len ); // allocate struct and buffer e->buf_len = buf_len; //

Equivalent of dwAllocationGranularity in Linux?

时光毁灭记忆、已成空白 提交于 2019-12-11 01:15:31
问题 What is the equivalent of dwAllocationGranularity in Linux? In Windows, it's defined as: The granularity for the starting address at which virtual memory can be allocated. Note that this is not the same thing as PAGE_SIZE , which is the granularity of a physical page. (On Windows, the virtual address granularity is 64 KiB on x86, whereas the page size is of course 4 KiB.) 回答1: The nearest equivalent of VirtualAlloc on Linux is mmap which, like VirtualAlloc, allows you to specify a desired

Recycle Freed Objects

孤人 提交于 2019-12-10 18:09:55
问题 suppose I need to allocate and delete object on heap frequently (of arbitrary size), is there any performance benefit if instead of deleting those objects, I will return it back to some "pool" to be reused later? would it give benefit by reduce heap allocation/deallocation?, or it will be slower compared to memory allocator performance, since the "pool" need to manage a dynamic collection of pointers. my use case: suppose I create a queue container based on linked list, and each node of that