473,320 Members | 1,978 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,320 software developers and data experts.

extend/shrink heap ?

From memory management perspective, how to code in c to create a managed
heap
that can be extended and shrunk ?
Thanks for help in advance.

Qingzhu
Nov 14 '05 #1
10 2360
Liu, Qingzhu [CAR:2N84:EXCH] wrote:
From memory management perspective, how to code in c to create a managed
heap
that can be extended and shrunk ?
Thanks for help in advance.

Considering the fact that doing so -- if you can at all -- is platform
specific, addressing your question to a newsgroup specific to your
platform is the right way to go. Here, you're off topic.

HTH,
--ag

--
Artie Gold -- Austin, Texas

"Yeah. It's an urban legend. But it's a *great* urban legend!"
Nov 14 '05 #2
Liu, Qingzhu [CAR:2N84:EXCH] wrote:
From memory management perspective, how to code in c to create a managed
heap
that can be extended and shrunk ?
Thanks for help in advance.

Qingzhu


First off, the C language does not require an implementation
to have a heap. There is automatic memory and dynamic memory.

If you would like to manage the dynamic memory yourself,
then use malloc() and allocate a huge chunk.

As far as shrinking or expanding a program's dynamic memory,
that is up to the operating system and best discussed in a
newsgroup devoted to your operating system.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Nov 14 '05 #3

"Liu, Qingzhu [CAR:2N84:EXCH]" <ql**@americasm01.nt.com>
From memory management perspective, how to code in c to create a > managed heap that can be extended and shrunk ?

The basic way to implement a meory allocation scheme is to declare an arena

static BLOCK arena[100000];

You then allocate blocks which consist of

typedef struct block
{
struct block *next;
size_t size;
}BLOCK;

The free list consists of a linked list of a a series of blocks. Initially
the whole arena is one big free block. When you allocate, walk the free
list until you find a block that is large enough. Then you spilt it and
return the pointer that is immediately after the control block.
When you free, walk the free list until you find the place where the ponter
is greater than the preceding and less than the following block, then you
have to add the block to the free list and consolidate if possible.
The trick is that you always return the control block +1, so the size is
always stored immediately before the memory you allocate.

If you know the arena size at compile time, simply hard code it in. If you
have to query the operating system to know how much memory you are allowed
to use, you leave the realms of comp.lang.c, and you will have to ask in a
platform-specific group.
Nov 14 '05 #4
Liu, Qingzhu wrote:
From memory management perspective,
how to code in C to create a managed heap
that can be extended and shrunk?


I used Google

http://www.google.com/

to search for

+"Data structures and algorithms" +"free list"

and found lots of stuff.

Nov 14 '05 #5
On Tue, 10 Feb 2004 14:55:56 -0600, in comp.lang.c , Artie Gold
<ar*******@austin.rr.com> wrote:
Liu, Qingzhu [CAR:2N84:EXCH] wrote:
From memory management perspective, how to code in c to create a managed
heap
that can be extended and shrunk ?
Thanks for help in advance.

Considering the fact that doing so -- if you can at all -- is platform
specific, addressing your question to a newsgroup specific to your
platform is the right way to go. Here, you're off topic.


I don't agree. You can implement one in Standard C if you want to. You're
confusing the existence or otherwise of some heap that the implementation
may use, with the creation of a user-defined heap of your own.

I do think its more of an algo question first tho. Work out the algo
(pehaps in comp.programming) , then work out how to code it in C.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #6
Mark McIntyre wrote:
On Tue, 10 Feb 2004 14:55:56 -0600, in comp.lang.c , Artie Gold
<ar*******@austin.rr.com> wrote:

Liu, Qingzhu [CAR:2N84:EXCH] wrote:
From memory management perspective, how to code in c to create a managed
heap
that can be extended and shrunk ?
Thanks for help in advance.

Considering the fact that doing so -- if you can at all -- is platform
specific, addressing your question to a newsgroup specific to your
platform is the right way to go. Here, you're off topic.

I don't agree. You can implement one in Standard C if you want to. You're
confusing the existence or otherwise of some heap that the implementation
may use, with the creation of a user-defined heap of your own.


Managing a "heap" is one thing, but "expanding or shrinking" in standard
C? I just don't see it (unless, of course, you're willing to have it
move around, too).

I do think its more of an algo question first tho. Work out the algo
(pehaps in comp.programming) , then work out how to code it in C.

Cheers,
--ag

--
Artie Gold -- Austin, Texas

"Yeah. It's an urban legend. But it's a *great* urban legend!"
Nov 14 '05 #7
Artie Gold <ar*******@austin.rr.com> wrote:
Mark McIntyre wrote:
On Tue, 10 Feb 2004 14:55:56 -0600, in comp.lang.c , Artie Gold
<ar*******@austin.rr.com> wrote:
Considering the fact that doing so -- if you can at all -- is platform
specific, addressing your question to a newsgroup specific to your
platform is the right way to go. Here, you're off topic.


I don't agree. You can implement one in Standard C if you want to. You're
confusing the existence or otherwise of some heap that the implementation
may use, with the creation of a user-defined heap of your own.


Managing a "heap" is one thing, but "expanding or shrinking" in standard
C? I just don't see it (unless, of course, you're willing to have it
move around, too).


Well, apart from realloc(), you can in fact allocate it in chunks and
put those in a linked list, if necessary.

Richard
Nov 14 '05 #8
Richard Bos wrote:
Artie Gold <ar*******@austin.rr.com> wrote:

Mark McIntyre wrote:
On Tue, 10 Feb 2004 14:55:56 -0600, in comp.lang.c , Artie Gold
<ar*******@austin.rr.com> wrote:
Considering the fact that doing so -- if you can at all -- is platform
specific, addressing your question to a newsgroup specific to your
platform is the right way to go. Here, you're off topic.

I don't agree. You can implement one in Standard C if you want to. You're
confusing the existence or otherwise of some heap that the implementation
may use, with the creation of a user-defined heap of your own.


Managing a "heap" is one thing, but "expanding or shrinking" in standard
C? I just don't see it (unless, of course, you're willing to have it
move around, too).

Well, apart from realloc(), you can in fact allocate it in chunks and
put those in a linked list, if necessary.


Of course. <splat -- sound of palm of hand hitting forehead>.
[Oh how I hate cerebral flatulence.]

Cheers,
--ag

--
Artie Gold -- Austin, Texas

"Yeah. It's an urban legend. But it's a *great* urban legend!"
Nov 14 '05 #9
On Tue, 10 Feb 2004 17:09:38 -0600, in comp.lang.c , Artie Gold
<ar*******@austin.rr.com> wrote:
Managing a "heap" is one thing, but "expanding or shrinking" in standard
C?
whats wrong with realloc?
I just don't see it (unless, of course, you're willing to have it
move around, too).


I don't have a problem with that. Did the OP say he did? I can't recall.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #10
Mark McIntyre wrote:
<ar*******@austin.rr.com> wrote:
Liu, Qingzhu [CAR:2N84:EXCH] wrote:

From memory management perspective, how to code in c to create
a managed heap that can be extended and shrunk ?


Considering the fact that doing so -- if you can at all -- is
platform specific, addressing your question to a newsgroup
specific to your platform is the right way to go. Here, you're
off topic.


I don't agree. You can implement one in Standard C if you want to.
You're confusing the existence or otherwise of some heap that the
implementation may use, with the creation of a user-defined heap
of your own.


True enough. My nmalloc for DJGPP is an example, where the debug
version (controlled by defines) uses an auxiliary program (the
debug exercizer) to malloc a large arena and simulate the action
of sbrk() (non-standard). Unfortunately the addresses returned
are not necessarily constant with changes in the code, so it
doesn't serve properly for regression testing.

To the OP: you can find nmalloc on my site, download section.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #11

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

Similar topics

1
by: R Camarda | last post by:
Help, I have a database that has a data file of 2GB and a log file of 31GB. In enterprise manager, when I choose shrink it says there is 30GB of unused space. When I shrink the database, it does...
5
by: BashiraInTrouble | last post by:
Hi Friends, I have tried almost everything but I cant seem to shrink the transaction log. Executing DBCC SQLPERF(LOGSPACE) gives me this info: Database Log Size (MB) Log Space Used (%) ...
8
by: Joseph Turian | last post by:
Fellow hackers, Is it possible to shrink the capacity of a vector? i.e. Without new'ing and delete'ing a vector, can one return its memory to the heap? Here's what I get under the g++...
4
by: Tommy.Vincent | last post by:
hi all, This will be a easy question for all out here. I have a database of 28GB. having 3 Data Files 22 GB, 3.58 Gb and 2.70 GB respectively. and a Transaction Log file of 156 mb. When i...
4
by: Bob Richardson | last post by:
Is it possible for an image to SHRINK (both height and width, keeping same h/w ratio) when the browser's width is reduced? It's easy to have both h & w increase, as needed, to fill up 100% of the...
4
by: Gary Bond | last post by:
Hi All, Can anybody point me to some 'how-to' documentation, tutorials, etc as to how to write a shrink/protect wrapper for .Net exes/dlls, (like the Shrinkwrap product for instance). I have...
12
by: hallpa1 | last post by:
Hi all, I posted messages before about trying to purge many records (about 35%) of a 200Gig database. The responses gave me a lot to think about, especially regarding the indexes. But due to the...
3
by: Galka | last post by:
Hello Environment: Windows XP, MS Access 2003. I'd like - in a report - to save space , when there is no company data. When there is, I print out company name, address, telephone number and...
6
by: Major Drake | last post by:
Windows 2003 64 bit sp2 + SQL Server std 32 bit sp2 compability mode 90, recovery model simple. I have about 40 Gb database where is about 98% free space (I deleted data from tables). dbcc...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.