473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Controlling memory allocation

Let's say I have an OS that can't limit the amount of memory a process
is allowed to consume, but I want to run some Python code in a
simulated low memory environment...

Is there a way to tell Python to limit the size of it's heap? Can you
ask it to use a function other than malloc through the C API? Any
stunts you might recommend to achieve the same results?

Chad

Sep 4 '05 #1
3 1883
Hello.
I have done the thing you are requesting. You can easily create your
own memory pool and have Python to use it.

I added some rows to Pyconfig.h:

#ifdef malloc
#undef malloc
#endif /*malloc*/
#define malloc Python_malloc

Then I have some overhead in my own Python_malloc(size_t nBytes)

Sep 5 '05 #2
Good to know that works :)

Did you also do the same for free and realloc to keep up with your
accounting?

The more I thought about it, the more I realized that calls to other
library functions could cause address space expansion if that code
internally called malloc or mmap.

See, I can use the OS to limit stack and data segment growth, but on OS
X/Darwin, it seems malloc uses mmap instead of brk to get more memory,
so setting a ulimit on the data segment doesn't work, because
technically the data segment doesn't grow during a malloc. Setting a
ulimit on the RSS (resident set size) doesn't work either as that limit
seems to only limit the number of pages the process is allowed to touch
(keep resident in memory) and the address range is still allowed to
expand.

Chad

To**********@gmail.com wrote:
Hello.
I have done the thing you are requesting. You can easily create your
own memory pool and have Python to use it.

I added some rows to Pyconfig.h:

#ifdef malloc
#undef malloc
#endif /*malloc*/
#define malloc Python_malloc

Then I have some overhead in my own Python_malloc(size_t nBytes)


Sep 5 '05 #3
Yep!
I redirect Free, Realloc and Malloc. (calloc is never used by Python).

"The more I thoug..."
That could be a possible problem. I will look in to it today and try
and find out if that occurs and in that case how often.
//T

Sep 6 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
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...
4
by: PaulR | last post by:
Hi, We have a Server running SLES 8 and 3GB memory, with 1 DB2 instance and 2 active Databases. General info... DB2level = "DB2 v8.1.0.72", "s040914", "MI00086", and FixPak "7" uname -a =...
62
by: ivan.leben | last post by:
How can I really delete a preloaded image from memory/disk cache? Let's say I preload an image by creating an Image object and setting its src attribute to desired URL: var img = new Image();...
66
by: Johan Tibell | last post by:
I've written a piece of code that uses sockets a lot (I know that sockets aren't portable C, this is not a question about sockets per se). Much of my code ended up looking like this: if...
24
by: Ken | last post by:
In C programming, I want to know in what situations we should use static memory allocation instead of dynamic memory allocation. My understanding is that static memory allocation like using array...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
34
by: jacob navia | last post by:
Suppose that you have a module that always allocates memory without ever releasing it because the guy that wrote it was lazy, as lazy as me. Now, you want to reuse it in a loop. What do you do?...
14
by: vivek | last post by:
i have some doubts on dynamic memory allocation and stacks and heaps where is the dynamic memory allocation used? in function calls there are some counters like "i" in the below function. Is...
66
by: karthikbalaguru | last post by:
Hi, Will 'free' return the memory Immediately to the OS ? Thx in advans, Karthik Balaguru
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.