Hi all,
I am trying to create a custom tuple type. I want it to live in a
custom memory region, which will be a memory-mapped file. Its
contents cannot be PyObject*. They have to be offsets into mapped
memory. GetItem( i ) would return:
(PyObject *)( t->ob_item[ i ]+ mmap_base_addr );
In the constructor, each item x would be stored as:
BYTE* x_offset= x- mmap_base_addr;
t->ob_item[ 0 ]= x_offset;
For starters, only ints, strings, and other tuples will be members.
I'll work out the list type and user-defined classes at a later time.
Each will be required to be already existing in the mmap; that is, be
of custom types too.
I had partial success with strings and ints just memcpy-ing the entire
PyObject structure. They are easier because they are immutable, and
don't contain references. That's why tuple is my next step: it's
immutable, but can contain references.
I want to back up a step and ask some questions about ints first.
What worries are there in memcpy-ing a PyIntObject? Would it be
better to compile my own MmapIntObject? I do Py_INCREF on the object
I return, to ensure it lives on, but I am getting an occasional crash
on exit. What did I miss? Do I need to readjust the ob_type pointer
every time I load the module (and lock for exclusive access)? Does
Python try to free the memory when it exits?
For the tuples, is there any way I can reuse the tuple code? The
constructor uses a custom pool for speed which I'd probably eliminate,
for the time. Slices would have to be MmapTupleObject instances too.
Should I also create MmapTupleIterOb ject?
PyObject_GC_New and PyObject_GC_New Var are confusing. I can't follow
them to the actual call to 'malloc', since they themselves lead around
Python's custom memory pool. What steps do I need to be sure to take
in my own?
I'm having trouble building PerstTupleObjec t.c (persistent tuple
object) to try it out. I'm using MinGW on WinXP. I added #include
"persttupleobje ct.h" to the top of "persttupleobje ct.c" already, but
it's a duplicate otherwise, with the name replaced.
---
C>c:/programs/mingw/bin/g++ persttupleobjec t.c -c -Ic:/programs/
python25/include
persttupleobjec t.c:650: warning: 'PyPerstTuple_T ype' defined locally
after being
referenced with dllimport linkage
C>c:/programs/mingw/bin/g++ -shared persttupleobjec t.o -o
persttupleobjec t.pyd -L
c:/programs/python25/libs -lpython25
persttupleobjec t.o(.text+0xce) :persttupleobje ct.c: undefined reference
to `_imp_
_PyPerstTuple_T ype'
persttupleobjec t.o(.text+0x15c ):persttupleobj ect.c: undefined
reference to `_PyG
C_generation0'
[snip]
---
I get some of the same errors when compiling tupleobject.c from the
Python-2.5.2 distribution:
C>c:/programs/mingw/bin/g++ tupleobject.c -c -Ic:/programs/python25/
include
tupleobject.c:6 49: warning: 'PyTuple_Type' defined locally after being
reference
d with dllimport linkage
C>c:/programs/mingw/bin/g++ -shared tupleobject.o -o tupleobject.pyd -
Lc:/progra
ms/python25/libs -lpython25
c:/programs/python25/libs/libpython25.a(d cbbs00622.o)(.t ext+0x0):
multiple defin
ition of `PyTuple_Type'
tupleobject.o(. data+0x140):tup leobject.c: first defined here
tupleobject.o(. text+0x15c):tup leobject.c: undefined reference to
`_PyGC_generati
on0'
[snip]
---
Thanks in advance. 0 887 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brian Genisio |
last post by:
Hi all,
I am developing some software, that creates a tree of information. For
each node, currently I am overriding the new operator, because it is a
requirement that after initialization, no new memory may be allocated.
It also needs to be thread safe, and each thread has a context, so any
allocation of nodes currently looks like this:
new (context) Node(...);
|
by: chris |
last post by:
Hi all,
I need to know, what is the difference between dynamic memory
allocation, and stack allocation ?
1. If I have a class named DestinationAddress, when should I use
dynamic memory allocation to create object of that class ?
2. If it says "dynamic memory allocation", is it mean the
following code :
DestinationAddress* dest = new DestinationAddress(); // code 1
|
by: Jeff Rodriguez |
last post by:
Main just loops over this while it's not null. The segfault occurs at
this line:
*line = (char)ch;
Also, please don't just fix the code. I would like to know why exactly
this isn't working so I can avoid problems with it in the future.
If there are any references I should check out let me know.
Full highlighted code at:
|
by: Franz |
last post by:
Greetings,
I have created the following types:
typedef struct _tbl_certificate{
int cert_id;
char *cert_name;
}tbl_certificate;
typedef struct _cameraObj{
tbl_camera camera;
|
by: Robert Frunzke |
last post by:
Hello,
I need to implement a custom allocator to speed up the allocation of a
specific class in my project and instead of hardwiring it, I would
"templatize"(?) it. The allocator should have minimal overhead and be
used for allocation of a large number of "Node" classes which represent
a hierarchical structure.
The custom allocator has to be at least intrusive as possible for the
user. The allocator has to be somehow bound to the...
| |
by: toton |
last post by:
Hi,
I have little confusion about static memory allocation & dynamic
allocation for a cluss member.
I have class like
class Bar{
public:
explicit Bar(){
cout<<"bar default"<<endl;
}
|
by: jubei |
last post by:
I've been trying to write a custom widget for a project, however when i try to run code that uses it i get the following error
> ./nokiagui.py
Traceback (most recent call last):
File "/home/jubei/code/nokia/trunk/nokiagui.py", line 427, in ?
gui = NewGui()
File "/home/jubei/code/nokia/trunk/nokiagui.py", line 193, in __init__
button = pkylib.ComboButton(("foo","bar","baz"))
File "/home/jubei/code/nokia/trunk/pkylib.py",...
|
by: joe |
last post by:
I have written a custom std allocator which follows the example in
Stroustrup's book.
I'm seeing a behavior I don't understand.
My allocate method within the allocator looks like the following:
(FooAllocator<T>)
pointer allocate(size_type cnt, typename
std::allocator<void>::const_pointer hint = 0)
|
by: jsanshef |
last post by:
Hi,
after a couple of days of script debugging, I kind of found that some
assumptions I was doing about the memory complexity of my classes are
not true. I decided to do a simple script to isolate the problem:
class MyClass:
def __init__(self,s):
self.mystring = s
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |