allocation

Runtime vs compile time memory allocation in java

时间秒杀一切 提交于 2019-12-06 06:08:29
问题 I am confused regarding whether memory allocation in java occurs at run time or compile time. For example: class Test{ int a; public Test(){ a=10; } }; // somewhere else Test t = new Test(); Is a allocated at run time or at compile time? If at compile time, how is it possible as java runs on a VM which directly takes compiled .class files? Also: when is a assigned the value 10 ? how does it work for reference variable t ? Thanks. 回答1: Compile time no memory allocation happens. Only at load

To “new” or not to “new”

隐身守侯 提交于 2019-12-06 01:59:14
问题 Is there a rule of thumb to follow when to use the new keyword and when not to when declaring objects? List<MyCustomClass> listCustClass = GetList(); OR List<MyCustomClass> listCustClass = new List<MyCustomClass>(); listCustClass = GetList(); 回答1: In your scenario it seems that the actual creation of the object is being performed inside your GetList() method. So your first sample would be the correct usage. When created, your List<MyCustomClass> is stored in the heap, and your listCustClass

c++ dynamic memory allocation limit

痞子三分冷 提交于 2019-12-06 00:24:41
Is there any kind of limit, system or otherwise, for dynamic allocation with new or malloc in C++? The system is 64bit and I want to allocate an array of some ~800million structs. Edit: The reason I didn't test it on my own before was because I don't currently have access to a machine with enough memory, so I felt that there was no point testing it on my current machine. After running my own tests, I can allocate 800million elements fine, but malloc returns NULL once I hit ~850million. The struct contains 7 floats, so the total size is about 22GB. What's the reason behind this seemingly

Alignment restrictions for malloc()/free()

谁说我不能喝 提交于 2019-12-05 21:58:25
问题 Older K&R (2nd ed.) and other C-language texts I have read that discuss the implementation of a dynamic memory allocator in the style of malloc() and free() usually also mention, in passing, something about data type alignment restrictions. Apparently certain computer hardware architectures (CPU, registers, and memory access) restrict how you can store and address certain value types. For example, there may be a requirement that a 4 byte ( long ) integer must be stored beginning at addresses

Bad allocation exceptions in C++

安稳与你 提交于 2019-12-05 16:41:43
问题 In a school project of mine I was requested to create a program not using STL. In the program I use alot of Pointer* = new Something; if (Pointer == NULL) throw AllocationError(); My question is about allocation errors: 1. is there an automatic exception thrown by new when allocation fails? 2. if so how can I catch it if I'm not using STL ( #include "exception.h ) 3. is using the NULL testing enugh? thank you. I'm using eclipseCDT(C++) with MinGW on windows 7. 回答1: Yes, the new operator will

How to copy values from an array into a new one?

守給你的承諾、 提交于 2019-12-05 16:08:54
I've been trying to figure this out off and on for a week now and I keep running into problems. My objective: Write a function that allocates memory for an integer array. The function takes as an argument an integer pointer, the size of the array, and newSize to be allocated. The function returns a pointer to the allocated buffer. When the function is first called, the size will be zero and a new array will be created. If the function is called when the array size is greater than zero, a new array will be created and the contents of the old array will be copied into the new array. Your

What is “dirty” memory in Instruments?

白昼怎懂夜的黑 提交于 2019-12-05 09:37:57
When I monitor my application using instruments and the instrument "allocations" I see a big amount of memory being marked as "dirty". What does that mean? I have no memory leaks in my application yet this pile of "dirty" memory keeps increasing. Dirty is a computer term used to denote cached data that needs to be sync'ed with the main memory. Don't worry, since this is automatically done by the hardware. "...I am trying to find out what is using up all my memory." The WWDC 2010 Session 311 presentation, Advanced Memory Analysis with Instruments , includes a section on 'Responding to Memory

Return lazy iterator that depends on data allocated within the function

☆樱花仙子☆ 提交于 2019-12-05 05:00:15
I am new to Rust and reading The Rust Programming Language , and in the Error Handling section there is a "case study" describing a program to read data from a CSV file using the csv and rustc-serialize libraries (using getopts for argument parsing). The author writes a function search that steps through the rows of the csv file using a csv::Reader object and collect those entries whose 'city' field match a specified value into a vector and returns it. I've taken a slightly different approach than the author, but this should not affect my question. My (working) function looks like this: extern

Scanning process memory causes crash

允我心安 提交于 2019-12-04 20:49:30
i have injected my DLL into process and i try to scan memory for addresses with same value as mine, but it results in a crash after i get 1st address , it should be 10 addresses for(DWORD i = MEM_START; i< MEM_END ;i++) { VirtualQuery((void*)i,pMemInfo,sizeof(MEMORY_BASIC_INFORMATION)); if(pMemInfo->AllocationProtect == PAGE_READONLY || PAGE_EXECUTE_WRITECOPY || PAGE_READWRITE || PAGE_WRITECOMBINE) { if(*(DWORD*)i==1337) { addresses.push_back(i); } } } I believe my protection check is wrong but not quite sure. virtual memory scanner MEMORY_BASIC_INFORMATION mbi = {0}; unsigned char *pAddress =

What is considered “small” object in Go regarding stack allocation?

左心房为你撑大大i 提交于 2019-12-04 19:31:19
The code: func MaxSmallSize() { a := make([]int64, 8191) b := make([]int64, 8192) _ = a _ = b } Then run go build -gcflags='-m' . 2>&1 to check memory allocation details. The result: ./mem.go:10: can inline MaxSmallSize ./mem.go:12: make([]int64, 8192) escapes to heap ./mem.go:11: MaxSmallSize make([]int64, 8191) does not escape My question is why a is small object and b is large object? make 64KB will escape to heap and less will allocate in stack. Does the _MaxSmallSize = 32 << 10 is the reason? go env GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="