memory-management

QueryWorkingSet includes invalid pages in its result

若如初见. 提交于 2021-02-19 06:35:22
问题 I'm currently using a 64-bit Windows 7 with I'm using Windows 7. I'm playing around with some PSAPI (Process Status API) functions to learn a bit more about how Windows manages memory. I noticed, however, that QueryWorkingSet included entries from which I couldn't read (e.g. page 0, and you can't read 0x00000000 ). When trying it on 64-bit, it became apparent why this was the case: QueryWorkingSet is bugged on 32-bit, as the addresses are truncated (hence the multiple page 0 entries). Still,

How bad is declaring arrays inside a for loop in Java?

别来无恙 提交于 2021-02-19 05:20:04
问题 I come from a C background, so I admit that I'm still struggling with letting go of memory management when writing in Java. Here's one issue that's come up a few times that I would love to get some elaboration on. Here are two ways to write the same routine, the only difference being when double[] array is declared: Code Sample 1 : double[] array; for (int i=0; i<n; ++i) { array = calculateSomethingAndReturnAnArray(i); if (someFunctionOnArrays(array)) { // DO ONE THING } else { // DO SOME

How bad is declaring arrays inside a for loop in Java?

谁说胖子不能爱 提交于 2021-02-19 05:19:39
问题 I come from a C background, so I admit that I'm still struggling with letting go of memory management when writing in Java. Here's one issue that's come up a few times that I would love to get some elaboration on. Here are two ways to write the same routine, the only difference being when double[] array is declared: Code Sample 1 : double[] array; for (int i=0; i<n; ++i) { array = calculateSomethingAndReturnAnArray(i); if (someFunctionOnArrays(array)) { // DO ONE THING } else { // DO SOME

malloc does not guarantee returning physically contiguous memory

﹥>﹥吖頭↗ 提交于 2021-02-19 04:25:07
问题 I'm reading about virtual memory and my conclusions are the following: malloc(size); malloc does not guarantee to return physically contiguous memory. It guarantees to return virtually contiguous memory. Especially it is true when size > 4KB because 4KB is the size of page. (On Linux systems). Am I right or am I wrong? Please explain. 回答1: malloc does not guarantee returning physically contiguous memory yes It guarantees returning virtually contiguous memory yes Especially it is true when

What if NULL and size 0 are passed to realloc()?

依然范特西╮ 提交于 2021-02-19 01:18:51
问题 Is the behavior implementation defined? If NULL and size == 0 are passed to realloc() : int main(void) { int *ptr = NULL; ptr = realloc(ptr, 0); if(ptr == NULL) { printf("realloc fails.\n"); goto Exit; } printf("Happy Scenario.\n"); Exit: printf("Inside goto.\n"); return 0; } The above code should print "realloc fails", right? But it is not? I've read somewhere that this call to realloc may return NULL also. When does that happen? 回答1: This behavior is implementation defined. From the C

How python handles object instantiation in a ' for' loop

泄露秘密 提交于 2021-02-18 22:36:26
问题 I've got a highly complex class : class C: pass And I've got this test code : for j in range(10): c = C() print c Which gives : <__main__.C instance at 0x7f7336a6cb00> <__main__.C instance at 0x7f7336a6cab8> <__main__.C instance at 0x7f7336a6cb00> <__main__.C instance at 0x7f7336a6cab8> <__main__.C instance at 0x7f7336a6cb00> <__main__.C instance at 0x7f7336a6cab8> <__main__.C instance at 0x7f7336a6cb00> <__main__.C instance at 0x7f7336a6cab8> <__main__.C instance at 0x7f7336a6cb00> <__main__

Android process memory map

若如初见. 提交于 2021-02-18 08:02:14
问题 I try to understand the memory regions in the com.android.browser process [memory map below], and have a few questions: For the address ranges without a pathname, what are mapped here? There're multiple [stack:xxxx] regions, are they thread local stacks? If not, what are they? They seem to get mapped in many different locations scattered in the memory space. If assuming the stack is at the top of the user space, then the user space memory is 2GB, the rest 2GB taken by the kernel space. Is it

Dealing with large amounts of data in c++

[亡魂溺海] 提交于 2021-02-17 15:31:42
问题 I have an application that sometimes will utilize a large amount of data. The user has the option to load in a number of files which are used in a graphical display. If the user selects more data than the OS can handle, the application crashes pretty hard. On my test system, that number is about the 2 gigs of physical RAM. What is a good way to handle this situation? I get the "bad alloc" thrown from new and tried trapping that but I still run into a crash. I feel as if I'm treading in nasty

Where is the heap?

六月ゝ 毕业季﹏ 提交于 2021-02-17 06:20:09
问题 I understand that in Linux the mm_struct describes the memory layout of a process. I also understand that the start_brk and brk mark the start and end of the heap section of a process respectively. Now, this is my problem: I have a process, for which I wrote the source code, that allocates 5.25 GB of heap memory using malloc . However, when I examine the process's mm_sruct using a kernel module I find the value of is equal to 135168. And this is different from what I expected: I expected brk

Are big endian and little endian values portable?

懵懂的女人 提交于 2021-02-16 18:22:51
问题 Hello i have a small dout in little endian and big endian i know this question has asked n no of times but i could not figure out some below points lets take int i=10 it is store in binary as 00000000 00000000 00000000 00001010 in stack section as below:- 00000000 |00000000 |00000000 |00001010 // In case of little endian MSB-------------------------------------------LSB Big endian 00001010 |00000000 |00000000 |00000000 // In case of in big endian MSB------------------------------------------