This problem involved me not knowing enough of C++. I am trying to access a specific value that I had placed in the Heap, but I'm unsure of how to access it. In my problem, I had placed a value in a heap from a data member function in an object, and I am trying to access it in another data member function. Problem is I do not know how, a...
I have a Java application that I run from a console which in turn exec's another Java process. I want to get a thread/heap dump of that child process. On Unix I could do a "kill -3 " but on Windows AFAIK the only way to get a thread dump is Ctrl-Break in the console. But that only gives me the dump of the parent process, not the child. I...
Is it possible to write a C function that does the following?
Allocate a bunch of memory in the heap
Writes machine code in it
Executes those machines instructions
Of course, I would have to restore the state of the stack to what it was prior to the execution of those machine instructions manually, but I want to know if this is feasi...
I've searched, but I've not understood very well these three concepts. When do I have to use dynamic allocation (in the heap) and what's its real advantage? What are the problems of static and stack? Could I write an entire application without allocating variables in the heap?
I heard that others languages incorporate a "garbage coll...
In the context of C++ (not that it matters):
class Foo{
private:
int x[100];
public:
Foo();
}
What I've learnt tells me that if you create an instance of Foo like so:
Foo bar = new Foo();
Then the array x is allocated on the heap, but if you created an instance of Foo like so:
Foo bar;
Then it's created o...
UPDATE So totally pulled a tool moment. I really meant by reference versus Out/Ref. Anything that says 'ref' I really meant by reference as in
SomeMethod(Object someObject)
Versus
SomeMethod(out someObject)
Sorry. Just don't want to change the code so the answers already make sense.
Far as I understand, unlike ref where it "cop...
Ignoring programming style and design, is it "safe" to call delete on a variable allocated on the stack?
i.e.
int nAmount;
delete &nAmount;
or
class sample
{
public:
sample();
~sample() { delete &nAmount;}
int nAmount;
}
...
I am aware of using jconsole to attach to a java process to get memory information. Specifically I'm after getting information on the various memory pools programatically so I can tie it to a monitoring application.
Thanks!
...
Using the STL's priority_queue I get the error "invalid heap" as soon as I try to use pop(). I can push my values into the queue, the top() of the queue is what I would expect and accessible. pop(), when it goes to re-heap, seems to have a problem.
I am storing pointers to a templated class in the queue. I have the comparision overloade...
From a SO answer about Heap and Stack, it raised me a question: Why it is important to know where the variables are allocated?
At another answer someone pointed that the stack is faster. Is this the only implication? Could someone give a code example where a simple allocation location change could solve a problem (eg. performance)?
Not...
I have the following code:
public class Test
{
public static void Main()
{
List<Person> list = new List<Person>();
Person person = new Person() { Name="Chris" };
list.Add(person);
person = new Person(){ Name="Wilson the cat" };
list.Add(person);
Console.WriteLine(list[0].Name);
Console.WriteL...
Hello, I fear that some of my code is causing memory leaks, and I'm not sure about how to check it. Is there a tool or something for MacOS X?
Thank you
...
I was told I can add the -XX:+HeapDumpOnOutOfMemoryError parameter to my JVM start up options to my JBoss start up script to get a heap dump when we get an out of memory error in our application. I was wondering where this data gets dumped? Is it just to the console, or to some log file? If it's just to the console, what if I'm not lo...
Is it considered bad manners/bad practice to explicitly place object members on the heap (via new)? I would think you might want to allow the client to choose the memory region to instantiate the object. I know there might be a situation where heap members might be acceptable. If you know a situation could you describe it please?
...
I've been programming for a while but It's been mostly Java and C#. I've never actually had to manage memory on my own. I recently began programming in C++ and I'm a little confused as to when I should store things on the stack and when to store them on the heap.
My understanding is that variables which are accessed very frequently shou...
I was looking for a rule of thumb for allocating objects on stack or heap in C++. I have found many discussions here on SO. Many people said, it's about the lifetime of an object. If you need more lifetime than the scope of the function, put it in the heap. That makes perfect sense.
But what made me confusing is, many people said, allo...
Hello,
I'm trying to understand what's going wrong with a program run in HP-UX 11.11 that results in a SIGSEGV (11, segmentation fault):
(gdb) bt
#0 0x737390e8 in _sigfillset+0x618 () from /usr/lib/libc.2
#1 0x73736a8c in _sscanf+0x55c () from /usr/lib/libc.2
#2 0x7373c23c in malloc+0x18c () from /usr/lib/libc.2
#3 0x7379e3f8 in _fi...
Hello, everyone
I know Java VM has "-XMx" and "-XMs" for setting the size of the heap. It also has a feature called "ergonomics", that can intelligently adjust the size of the heap. But, I have a problem at hand requiring the heap with strictly fixed size.
Here is the command line arguments:
"-Xms2m -Xmx2m -XX:+PrintGCDetails"
How...
I have an object(A) which has a list composed of objects (B). The objects in the list(B) are pointers, but should the list itself be a pointer? I'm migrating from Java to C++ and still haven't gotten fully accustomed to the stack/heap. The list will not be passed outside of class A, only the elements in the list. Is it good practice to a...
My issue is more semantic than functional, As the code does seem to implement the deQueue and enQueue functions correctly.
The reheapDown and reheapUp functions are being used incorrectly, And i believe the issue lies in my heap function
package priqueue;
public class Hosheap{
private Patient[] elements;
private int numElements;
...