I am wondering how difficult it would be to integrate a reference counting (or other managed memory) regime for managing some of my struct libraries in C. What sample code would you recommend I look at?
...
I was looking at the source code to the hasattr built-in function and noticed a couple of lines that piqued my interest:
Py_INCREF(Py_False);
return Py_False;
...
Py_INCREF(Py_True);
return Py_True;
Aren't Py_False and Py_True global values? Just out of sheer curiosity, why is Python keeping a reference count for these variables?
...
.NET profilers can show reference count to managed objects. How do they count them?
...
First of all, the problem is that program fails with double memory freeing ...
The deal is:
I have
FooCPlusPlus *obj;
and I pass it to my script. It works fine. Like this:
PyObject *pArgs, *pValue;
pArgs = Py_BuildValue("((O))", obj);
pValue = PyObject_CallObject(pFunc, pArgs);
where pFunc is a python function...
So, my script ha...
I was just writing some exploratory code to solidify my understanding of Objective-C and I came across this example that I don't quite get. I define this method and run the code:
- (NSString *)stringMethod
{
NSString *stringPointer = [[NSString alloc] initWithFormat:@"string inside stringPointer"];
[stringPointer release];
...
I am experimenting with overloading operator delete, so that I can return a plain pointer to those who don't wish to work with smart pointers, and yet be able to control when the object is deleted.
I define a class Cat that is constructed with several souls, has an overloaded operator delete that does nothing, and destructor that decrem...
I have an object which implements reference counting mechanism. If the number of references to it becomes zero, the object is deleted.
I found that my object is never deleted, even when I am done with it. This is leading to memory overuse. All I have is the number of references to the object and I want to know the places which referen...
I have a COM interface with a method that returns an object:
interface ICreatorInterface {
HRESULT CreateObject( IObjectToCreate** );
};
The key is that calling ICreatorInterface::CreateObject() is the only way to retrieve an object implementing IObjectToCreate interface.
In C++ I could do it this way:
HRESULT CCreatorInterface...
Hi,
I have a string of stock price data data and I want to be able to count how many days the price moves up or down lasted. So for example, from the data I have a used "if" functions to determine if a day was up or down: "U" for and Up day and "D" for a Down day. Lets say the string then looks like this:
UUUDDUDUDUDUUU
I want a for...
I recently had the following memory bug, which is easy to spot here, but can be harder to detect in more complex code:
class Foo : public IFoo {
const Bar& bar_;
public:
Foo(const Bar& bar) : bar_(bar) {
}
void test() {
// access bar_ here
}
};
int baz() {
IFoo* foo = NULL;
if(whatever) {
Bar bar;
foo = new Fo...
Assume you have a reference counted object in shared memory. The reference count represents the number of processes using the object, and processes are responsible for incrementing and decrementing the count via atomic instructions, so the reference count itself is in shared memory as well (it could be a field of the object, or the objec...
I have rephrased this question.
When .net objects are exposed to COM Clients through COM iterop, a CCW (COM Callable Wrapper) is created, this sits between the COM Client and the Managed .net object.
In the COM world, objects keep a count of the number of references that other objects have to it. Objects are deleted/freed/collected whe...
Say a server stores objects with a reference count. Clients, when they connect (over sockets), send messages to increment and decrement the counts on those objects. The only behavior pattern that's guaranteed is that if a client works with a particular object, it will increment it, some time will pass, and it will decrement it (clients n...
Here's my understanding of it:
Object are only retained (reference counter is incremented):
when init from NSObject is called.
when retain is called.
Objects are only released (reference counter is decremented):
when release is called.
when an autorelease pool containing the object is drained
And to clarify, autorelease does no...
I'm writing a program that for performance reasons uses shared memory (sockets and pipes as alternatives have been evaluated, and they are not fast enough for my task, generally speaking any IPC method that involves copies is too slow). In the shared memory region I am writing many structs of a fixed size. There is one program responsibl...
Most common re-usable reference counted objects use private inheritance to implement re-use. I'm not a huge fan of private inheritance, and I'm curious if this is an acceptable way of handling things:
class ReferenceCounter {
std::size_t * referenceCount;
public:
ReferenceCounter()
: referenceCount(NULL) {};
Referenc...
Just for the sheer heck of it, I've decided to create a Scheme binding to libpython so you can embed Python in Scheme programs. I'm already able to call into Python's C API, but I haven't really thought about memory management.
The way mzscheme's FFI works is that I can call a function, and if that function returns a pointer to a PyObj...
On the slides I am revising from it says the following:
Live objects can be identified either by maintaining a count of the number of references to each object, or by tracing chains of references from the roots.
Reference counting is expensive – it needs action every time a reference changes and it doesn’t spot cyclical structur...
For debugging reasons I want to destroy a class instance which still as references. Is that possible? It doesn't have to be elegant or stable, because this'll never end up in production code.
To clarify:
Public Sub Main
Dim o as MyClass
Set o = New MyClass //o is created, one reference
DestroyObject o //Class_Terminate ...
in this example
procedure foobar;
var tab:array of integer;
begin
setlength(tab,10);
end;
is the array destroyed or the memory is leaking?
...