Basically I'd like to do something like that:
int[3] array_func()
{
return {1,1,1};
}
int main(int argc,char * argv[])
{
int[3] point=array_func();
}
But that doesn't seem legal in C++. I know I can use vectors, but since I know the size of the array is a constant, it seems like a loss of performance is likely to occur.
I'd a...
I'm trying to make a pointer point to a 2D array of pointers. what is the syntax and how would i access elements.
...
Do the JVM and .NET VM allocate objects on the stack when it is obvious to the runtime that an objects lifetime is limited to a certain scope?
...
Hi, I'm doing some assignment and got stuck at one point here.
I am trying to write an list_add() function. The first functionality of it is to add values to the array. The second functionality for it is to increase the size of the array. So it works much like a vector. I dunno if I get it right though. What I tried is to create a new dy...
All,
This has been bugging me for a while now. In C\C++( i guess java and .NET as well) we do not have to specify the row index in a multi-dimensional array.
So, for example i can declare an array of ints as such:
int Array[][100];
I think static arrays in general are represented as contiguous memory on the stack. So, taking a column...
Hi,
I have some trouble with allocate array of arrays in CUDA.
void ** data;
cudaMalloc(&data, sizeof(void**)*N); // allocates without problems
for(int i = 0; i < N; i++) {
cudaMalloc(data + i, getSize(i) * sizeof(void*)); // seg fault is thrown
}
What did I wrong?
...
It is my understanding that, in addition to allocating memory, alloc sets all instance variables (with the exception of the isa variable) to zero or to the equivalent type for zero, such as nil, NULL, and 0.0.
But I recently read the following about init:
Initialization sets the instance
variables of an object to reasonable
and ...
So I have a couple of structs...
struct myBaseStruct
{
};
struct myDerivedStruct : public myBaseStruct
{
int a, b, c, d;
unsigned char* ident;
};
myDerivedStruct* pNewStruct;
...and I want to dynamically allocate enough space so that I can 'memcpy' in some data, including a zero-terminated string. The size of the base struct...
Here's some C++ code that just looks funny to me, but I know it works.
There is a struct defined, and in the program we allocate memory using a void pointer. Then the struct is created using the allocated buffer.
Here's some code
typedef struct{
char buffer[1024];
} MyStruct
int main()
{
MyStruct* mystruct_ptr = 0;
void* ...
Hi all,
typedef struct
{
struct table **symbols; // array of the stack
int top; //index of the top element
int size; //maximum size of the stack
}stack;
void *createStack(int size)
{
stack *stck;
stck = (stack *) malloc(sizeof(stack));
stck->symbols = ....
stck->size = size;
stck->top = -1;
printf("stack is created...
Hi,
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?
...
How to write a thread-safe and efficient, lock-free memory allocator in C? By efficient I mean:
Fast allocation & deallocation
Optimal memory usage (minimal wastage and no external fragmentation)
Minimal meta-data overhead
...
What I need is a system I can define simple objects on (say, a "Server" than can have an "Operating System" and "Version" fields, alongside other metadata (IP, MAC address, etc)).
I'd like to be able to request objects from the system in a safe way, such that if I define a "Server", for example, can be used by 3 clients concurrently, the...
I'm maintaining a plugin (implemented as a dll) for a big closed source application. This has been working fine for years. However, with the latest update to it's SDK the vendor overloaded global operators new and delete. This causes lots of trouble for me. What happens is that my plugin allocates a string. I pass this string into a stat...
Hi,
I want to make a game of TicTacToe. WhenI resize the window I want to appear more buttons on the interface. From a matrix of 3x3 to 4x4 etc up to 9x9, depending on how much I resize the window. How do I do this?
I will make a free web site design to whoever provides me with a working answer (and something extra for the full program...
Hi All,
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...
I'm getting memory allocation errors (and a subsequent crash) on the following simplified code:
std::wstring myKey = L"str_not_actually_constant";
MyType obj;
Read( obj );
std::map<std::wstring, MyType> myMap;
myMap[myKey] = obj; // Sometimes allocation error (1)
...
Read( MyType& obj )
{
obj.member1 = ReadFromFuncThatMayBeProblem()...
The following piece of code observed under JConsole shows a constant increase of the heap size. The heap reach a maximum of 25mb and then the GC runs and decease the heap size to almost 3MB. Is this the expected behavior ? I'm very surprised!
public class Dummy {
public static void main(String[] args) {
System.out.println("...
Hi, I'm overriding the new operator to manually allocate heap space when using the new keyword.
Usually using a stack-allocated heap container with pointers to its items-
CArray<CObject*> objects;
-is fine. but I'm picky and I want to make buffers-
CArray<CObject> objects;
-that let me modify POD types. So, I allocate them on the ...
When you allocate and initialize and object, and then want to return that object, how are you supposed to return it?
I have the following code:
NSXMLDocument* fmdoc = [[NSXMLDocument alloc] initWithContentsOfURL:trackInfoUrl options:NSXMLDocumentTidyXML error:&err];
return [fmdoc autorelease];
Is this correct?
...