allocation

Open jar from another jar

佐手、 提交于 2019-12-12 01:18:42
问题 The same old problem ... I want to run my jar on Mac or Linux with high memory allocation. I do not want the user to open the Terminal and write java -XMx512 -jar MainJar.jar manually. I have seen a lot of solutions to fix this ... But i was wondering if this might work : " Executing the Terminal command java -XMx512 -jar MainJar.jar in Jar(B) to initialize Jar(A) with 512 MB memory allocation. ". In Jar(B) i have tried this code to run Jar(A) and it worked fine : public static void main

malloc and gcc optimization

醉酒当歌 提交于 2019-12-12 00:31:44
问题 I've written some memory allocation code in c as an exercise. It is translated almost purely to macro now. By doing this I've been able to reduce allocation time to something similar to glibc malloc (unoptimized). However, running the test with gcc -Ox where x > 0, I can't get anywhere near glibc's speed -- glibc beats me by around 10^2 I understand that the glibc malloc implementation is based on Doug Lea's dlmalloc and the comments suggest the code does benefit from optimizing compilers. I

Android RenderScript copy allocation in rs file

丶灬走出姿态 提交于 2019-12-11 21:27:00
问题 I'm passing an allocation created from Bitmap into rs file, and inside the script I'm trying to copy the allocation to a new one using the rsAllocationCopy2DRange function, but I get force close when I'm trying to run the app. Can someone please explain how to use the function correctly, and what exactly are the arguments it gets. I looked in the reference site: http://developer.android.com/reference/renderscript/rs__allocation_8rsh.html#a7f7e2369b3ed7d7db31729b6db7ba07e but I still don't

How can I allocate just enough memory for one line of text read from a file in c

房东的猫 提交于 2019-12-11 19:11:55
问题 The objective of my program that I need to write is that it will read in a line from a file ONLY ONCE (meaning when you read it once you should not go back to the file and read it again), and it should store that line in an array of chars. The size of the array must be just big enough to hold the line of text in. Also, it is recommended to not use getchar, and instead use fgets. 回答1: Worst case, there is only one line of text in the file, so you would need to get the file size and allocate

Why this code doesn't allocate memory in C?

徘徊边缘 提交于 2019-12-11 17:24:51
问题 Updated question is here Memory allocation problem in HashTable I'm working on making a HashTable in C. This is what I've done. I think I'm going on a right path but when I'm trying to main.c HashTablePtr hash; hash = createHashTable(10); insert(hash, "hello"); insert(hash, "world"); HashTable.c HashTablePtr createHashTable(unsigned int capacity){ HashTablePtr hash; hash = (HashTablePtr) malloc(sizeof(HashTablePtr)); hash->size = 0; hash->capacity = capacity; ListPtr mylist = (ListPtr)calloc

C: Passing by reference during dynamic allocaion

*爱你&永不变心* 提交于 2019-12-11 17:04:10
问题 My code is to allocate and initialize the array as follows ( floatalloc2 is a function used to allocate the 2D array): #include <stdio.h> #include <stdlib.h> void alloc_arr(int adjwfd, int nx, int nz, float **G, float **L1, float **L2) { G = floatalloc2(nx, nz); switch (adjwfd){ case 1: L1 = floatalloc2(nx, nz); break; case 2: L2 = floatalloc2(nx, nz); break; } } void init_arr(int adjwfd, int nx, int nz, float **G, float **L1, float **L2) { memset(G[0],0,nx*nz*sizeof(float)); switch (adjwfd){

How work properly with array allocations in RenderScript

旧时模样 提交于 2019-12-11 16:12:11
问题 I've been working around with RenderScript for a few days, but I can't figure out how properly pass an array from Java to RenderScript. I saw some examples but none of them worked for me and I'm getting stuck with the lack of documentation. In this code I'm trying to do some checks between bb and coords array for each index in that root() receives: RenderScript code: #pragma version(1) #pragma rs java_package_name(com.me.example) int4 bb; rs_allocation coords; void __attribute__((kernel))

Java object creation and memory size

此生再无相见时 提交于 2019-12-11 13:10:32
问题 I am trying understand about the size that a Java object will be allocated with when created using a new operator. Consider that i am creating a class public class NewClass { NewClass() { } } when i create an instance of NewClass using NewClass nc = new NewClass(); . what is the size of the NewClass that gets created in the heap? ~ Jegan 回答1: Profiling is the best way, but you can get a good estimate like so: 8 bytes per object (bare overhead), plus fields. Primitive Fields: as listed in Java

C - Pointer memory allocation [duplicate]

前提是你 提交于 2019-12-11 12:05:19
问题 This question already has answers here : Why do we cast return value of malloc? [duplicate] (4 answers) Do I cast the result of malloc? (26 answers) Closed 4 years ago . Can someone please explain to me the difference between int *x = malloc(sizeof(int)); && int *x = (int*)malloc(sizeof(int)); Thanks! 回答1: The difference is that you are casting the return of malloc() in the second example. malloc() returns a void* pointer, which is automatically and safely promoted to any other pointer type

Wrapping unmanaged c++ in a managed wrapper

橙三吉。 提交于 2019-12-11 10:32:04
问题 I have an unmanaged C++ library. I would like to expose the functionality for .NET applications. There's one partucular function I am not sure how to handle: typedef void (free_fn*) (void*); void put (void *data, free_fn deallocation_function); The idea is that you pass dynamically allocated buffer to the function and supply a deallocation function. The library will process the data asynchronously and will release the buffer later on when data is no longer needed: void *p = malloc (100); ...