allocation

Dynamically allocate C struct?

社会主义新天地 提交于 2020-01-22 14:36:08
问题 I want to dynamically allocate a C struct: typedef struct { short *offset; char *values; } swc; Both 'offset' and 'values' are supposed to be arrays, but their size is unknown until runtime. How can I dynamically allocate memory for my struct and the struct's arrays? 回答1: swc *a = (swc*)malloc(sizeof(swc)); a->offset = (short*)malloc(sizeof(short)*n); a->values = (char*)malloc(sizeof(char)*n); Where n = the number of items in each array and a is the address of the newly allocated data

Why does my garbage collection log show 3.8GB as the max available heap size while I have allocated 4GB as the max heap size?

穿精又带淫゛_ 提交于 2020-01-19 17:11:56
问题 I have a 64-bit hotspot JDK version 1.7.0 installed on a 64-bit RHEL 6 machine. I use the following JVM options for my tomcat application. CATALINA_OPTS="${CATALINA_OPTS} -Dfile.encoding=UTF8 -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -Duser.timezone=EST5EDT" # General Heap sizing CATALINA_OPTS="${CATALINA_OPTS} -Xms4096m -Xmx4096m -XX:NewSize=2048m -XX:MaxNewSize=2048m -XX:PermSize=512m -XX:MaxPermSize=512m -XX:+UseCompressedOops -XX:+DisableExplicitGC" #

Why does my garbage collection log show 3.8GB as the max available heap size while I have allocated 4GB as the max heap size?

▼魔方 西西 提交于 2020-01-19 17:09:07
问题 I have a 64-bit hotspot JDK version 1.7.0 installed on a 64-bit RHEL 6 machine. I use the following JVM options for my tomcat application. CATALINA_OPTS="${CATALINA_OPTS} -Dfile.encoding=UTF8 -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -Duser.timezone=EST5EDT" # General Heap sizing CATALINA_OPTS="${CATALINA_OPTS} -Xms4096m -Xmx4096m -XX:NewSize=2048m -XX:MaxNewSize=2048m -XX:PermSize=512m -XX:MaxPermSize=512m -XX:+UseCompressedOops -XX:+DisableExplicitGC" #

Matlab: Can a large number of preallocations be placed in another file?

旧街凉风 提交于 2020-01-16 00:50:12
问题 I'm working on a matlab code where I have a lot of variables that need to be preallocated (each variable is 8760x1 double). The values are generated in a for loop: a=zeros(8760,1); b=zeros(8760,1); (...) for i=1:8760 a(i)=[some code]; b(i)=[some code]; (...) end However, seeing that I have a lot of these variables, I want to preallocate the parameters in another file (more clean). preallocate.m a=zeros(8760,1); b=zeros(8760,1); ... main.m preallocate for i=1:8760 a(i)=[some code]; b(i)=[some

How to make memory allocation in MSVC C++ deterministic?

有些话、适合烂在心里 提交于 2020-01-14 14:51:10
问题 While debugging some C++ code with tons of pointers it would be useful if the memory addresses between runs were the same. Is there any way to make the series of addresses that are returned between consecutive runs of a program that perform the same memory allocations deterministic? Maybe an environment variable or something that can be set for the debug heap? I am aware that there are many good reasons you want randomization for release builds, but determinism is handy for debugging in some

Return lazy iterator that depends on data allocated within the function

风格不统一 提交于 2020-01-13 09:24:06
问题 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

MatLab memory allocation when max size is unknown

只愿长相守 提交于 2020-01-11 06:22:09
问题 I am trying to speed up a script that I have written in Matlab that dynamically allocates memory to a matrix (basicallly reads a line of data from a file and writes it into a matrix, then reads another line and allocates more memory for a larger matrix to store the next line). The reason I did this instead of preallocating memory using zeroes() or something was that I don't know the exact size the matrix needs to be to hold all of the data. I also don't know the maximum size of the matrix, so

How to preallocate(reserve) a priority_queue<vector>?

若如初见. 提交于 2020-01-11 00:06:57
问题 How can I preallocate a std::priority_queue with a container of type std::vector ? std::priority_queue<unsigned char, std::vector<unsigned char>> pq; pq.c.reserve(1024); Does not compile because the underlying vector is a protected member. Is it possible to use the constructor of the priority_queue to wrap it around a pre-reserved vector? 回答1: Yes, there's a constructor for that. It's slightly tedious that you also have to specify a comparator: std::vector<unsigned char> container; container

iOS: Debugging memory leaks for UILabel in swift

放肆的年华 提交于 2020-01-06 20:23:47
问题 I new to profiling and using instruments in xcode. I am facing of problem of memory leaks in tableViewCell for UILabel(CALayer). In my code all the tableViewCell have a fixed view called bottomView. This bottomView may or may not contain UILabel which can be either directly within bottomView or within a subView of bottomView. Every time within the init method for cell I check for bottomView and remove it from superView and set it to nil. Then reinitialise the bottomView (using UIView(frame: )

How to determine if a buffer is freed or not

别来无恙 提交于 2020-01-05 07:46:12
问题 I use new to allocate a buffer, as follows: BYTE *p; p = new BYTE[20]; ... delete p; After p is deleted, if I do NOT assign NULL to p , is there a way to determine whether it has already been freed? 回答1: You cannot determine that, and that's one of the main reasons you usually rely on higher-level mechanisms to handle memory, such as smart pointers (shared_ptr, unique_ptr and so on), or in your case rather std::vector , to deal with raw memory in a way that guarantee no double delete ,