memory-management

Visual Studio 2010 C++: Get size of memory block allocated by malloc

扶醉桌前 提交于 2021-01-27 05:43:48
问题 How can I get, given a pointer to a block of memory allocated with malloc, the size of it? For example: void* ptr = malloc( 10 ); //Allocate 10 bytes printf( "%d", GetMemSize( ptr ) ); //Should print 10 I want to do this for debugging purposes. 回答1: In Visual C++ you can use _msize() for that. 回答2: The Microsoft CRT has a function size_t _msize(void *memblock); which will give you the size of the allocated block. Note this may be (and in fact is likely to be) larger than the size asked for,

what is uninitialized data in pytorch.empty function

笑着哭i 提交于 2021-01-27 05:33:13
问题 i was going through pytorch tutorial and came across pytorch.empty function. it was mentioned that empty can be used for uninitialized data . But, when i printed it, i got a value. what is the difference between this and pytorch.rand which also generates data(i know that rand generates between 0 and 1). Below is the code i tried a = torch.empty(3,4) print(a) Output: tensor([[ 8.4135e-38, 0.0000e+00, 6.2579e-41, 5.4592e-39], [-5.6345e-08, 2.5353e+30, 5.0447e-44, 1.7020e-41], [ 1.4000e-38, 5

what is uninitialized data in pytorch.empty function

倾然丶 夕夏残阳落幕 提交于 2021-01-27 05:32:23
问题 i was going through pytorch tutorial and came across pytorch.empty function. it was mentioned that empty can be used for uninitialized data . But, when i printed it, i got a value. what is the difference between this and pytorch.rand which also generates data(i know that rand generates between 0 and 1). Below is the code i tried a = torch.empty(3,4) print(a) Output: tensor([[ 8.4135e-38, 0.0000e+00, 6.2579e-41, 5.4592e-39], [-5.6345e-08, 2.5353e+30, 5.0447e-44, 1.7020e-41], [ 1.4000e-38, 5

JNI Object Pointers

别来无恙 提交于 2021-01-27 04:18:09
问题 Problem When experimenting with the JNI interface, I was wondering if I could take a JObject and transmute it into an equivalent struct to manipulate the fields. However, when I tried I was surprised to see that this did not work. Ignoring how horrible this idea might be, why didn't it work? My Approach Java Test Class I made a simple class Point to do my test. Point has two fields and a constructor that takes in an x and y as well as a few random methods that return information based on the

need of pointer objects in objective c

旧街凉风 提交于 2021-01-21 04:26:33
问题 A very basic question .. but really very important to understand the concepts.. in c++ or c languages, we usually don't use pointer variables to store values.. i.e. values are stored simply as is in: int a=10; but here in ios sdk, in objective c, most of the objects which we use are initialized by denoting a pointer with them as in: NSArray *myArray=[NSArray array]; So,the question arises in my mind ,that, what are the benefit and need of using pointer-objects (thats what we call them here,

How to free memory allocated by thread-function in the main

限于喜欢 提交于 2021-01-04 07:16:13
问题 I have allocated heap memory in the thread function f1 , this storage is used to calculate the value in the heap region so that the main function can see it. Here is the thread function definition: void *f1(void *input){ int sum = (int*)malloc(sizeof(int)); /* Do calculation */ pthread_exit((void*)&sum); } In the above code, the sum is the heap allocated storage, whose address is passed as a return value to the sum1 in the main() . I join the thread in the main() like this: void *sum1;

How to free memory allocated by thread-function in the main

我怕爱的太早我们不能终老 提交于 2021-01-04 07:15:19
问题 I have allocated heap memory in the thread function f1 , this storage is used to calculate the value in the heap region so that the main function can see it. Here is the thread function definition: void *f1(void *input){ int sum = (int*)malloc(sizeof(int)); /* Do calculation */ pthread_exit((void*)&sum); } In the above code, the sum is the heap allocated storage, whose address is passed as a return value to the sum1 in the main() . I join the thread in the main() like this: void *sum1;

Is it possible to allocate large amount of virtual memory in linux?

喜夏-厌秋 提交于 2021-01-02 06:45:17
问题 It would be efficient for some purposes to allocate a huge amount of virtual space, and page in only pages that are accessed. Allocating a large amount of memory is instantaneous and does not actually grab pages: char* p = new char[1024*1024*1024*256]; Ok, the above was wrong as pointed out because it's a 32 bit number. I expect that new is calling malloc which calls sbrk, and that when I access a location 4Gb beyond the start, it tries to extend the task memory by that much? Here is the full

Do I need to delete objects passed to google protocol buffer (protobuf)?

谁说我不能喝 提交于 2021-01-01 06:51:16
问题 I have simple messages: message SmallValue { int32 val = 1; } message Value { int32 val1 = 1; int32 val2 = 2; SmallValue val3 = 3; } message SendMessage { int32 id = 1; oneof message { Value value= 2; } My piece of code: // create new pointer for smallValue SmallValue* smallValue = new SmallValue(); smallValue->set_val3(3); // create new object value and set_allocated_val3 Value value; value.set_val1(1); value.set_val2(2); value.set_allocated_val3(smallValue); // create new object message and

Does userfaultfd now support file backed map?

 ̄綄美尐妖づ 提交于 2021-01-01 03:56:36
问题 I saw from the documentation of userfaultfd https://manpages.debian.org/testing/manpages-dev/userfaultfd.2.en.html http://man7.org/linux/man-pages/man2/ioctl_userfaultfd.2.html that userfaultfd will start supporting shared map since kernel 4.11. However, the documentation still looks very ambiguous in the sense that I'm still wondering will these include supporting file-backed mmap (which can also be MAP_SHARED)? 回答1: To answer definitively, since the information is not in the manual page(s),