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

Implementation of malloc

Hi All,
Can any one tell me how to implement malloc.
Thanks and Regards,
Raman Chalotra

Jan 30 '07 #1
10 7151
Raman wrote:
Can any one tell me how to implement malloc.
There's an example in K&R.

What's wrong with the one you've got?

--
Chris "electric hedgehog" Dollin
"Our future looks secure, but it's all out of our hands"
- Magenta, /Man and Machine/

Jan 30 '07 #2


On Jan 30, 1:39 pm, Chris Dollin <chris.dol...@hp.comwrote:
Raman wrote:
Can any one tell me how to implement malloc.There's an example in K&R.

What's wrong with the one you've got?

--
Chris "electric hedgehog" Dollin
"Our future looks secure, but it's all out of our hands"
- Magenta, /Man and Machine/

Actually I Got this question in A Interview .

Jan 30 '07 #3
Raman wrote:
Chris Dollin <chris.dol...@hp.comwrote:
>Raman wrote:
>>Can any one tell me how to implement malloc.

There's an example in K&R. What's wrong with the one you've got?

Actually I Got this question in A Interview .
You can't, and be portable. That's why it's a system function.
However, for DJGPP, and possibly some assortment of Unices, see
nmalloc.zip in:

<http://cbfalconer.home.att.net/download/>

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Jan 30 '07 #4
Raman wrote:

(don't quote signatures)
On Jan 30, 1:39 pm, Chris Dollin <chris.dol...@hp.comwrote:
>Raman wrote:
Can any one tell me how to implement malloc.There's an example in K&R.
Something broken when you quoted: my reply has been jammed on the end of
your question. Watch out for that.
>What's wrong with the one you've got?
Actually I Got this question in A Interview .
(fx:eyebrows) What's wrong with the one /they've/ got?

As I say, there's an example in K&R [1]. It's just code, apart from the
bit where you may have to interface to your local OS to claim free pages
or whatever it offers, and having to get alignments right. Lots of choices
to make. A /production/ malloc is, I'd guess, pretty hard to do well [2].

[1] Kernighan and Ritchie, The C Programming Language (second edition
preferred).

[2] But easy to do badly. Correctly, but badly.

--
Chris "electric hedgehog" Dollin
Nit-picking is best done among friends.

Jan 30 '07 #5
CBFalconer wrote:
Raman wrote:
>Chris Dollin <chris.dol...@hp.comwrote:
>>Raman wrote:

Can any one tell me how to implement malloc.

There's an example in K&R. What's wrong with the one you've got?

Actually I Got this question in A Interview .

You can't, and be portable.
You're thinking of alignment?

(I'm thinking of a large static array.)

--
Chris "electric hedgehog" Dollin
"Never ask that question!" Ambassador Kosh, /Babylon 5/

Jan 30 '07 #6
Chris Dollin wrote, On 30/01/07 09:44:
CBFalconer wrote:
>Raman wrote:
>>Chris Dollin <chris.dol...@hp.comwrote:
Raman wrote:

Can any one tell me how to implement malloc.
There's an example in K&R. What's wrong with the one you've got?
Actually I Got this question in A Interview .
You can't, and be portable.

You're thinking of alignment?
That is definitely a gotcha. You need to make some system specific
assumptions about what is enough to get the alignment correct for any type.
(I'm thinking of a large static array.)
When is sometimes a very good way of doing it.
--
Flash Gordon
Jan 30 '07 #7
"Raman" <ra***********@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
Hi All,
Can any one tell me how to implement malloc.
Thanks and Regards,
Raman Chalotra
Well, you can take a look at a high-performance multi-threaded allocator
algorithm I created:

http://groups.google.com/group/comp....c40d42a04ee855

Seriously, my invention is actually one of the fastest atomically
thread-safe virtually zero-overhead memory allocators currently out there.
It beats the pants off HOARD and runs circles around Maged Michael's
so-called lock-free memory allocator...

http://portal.acm.org/citation.cfm?id=996848

I guess this is somewhat on topic simply because the pseudo-code
implementation of the invention is in C... I can't wait for this thing to be
properly released... So far I haven't come across anything like it. It
simply has excellent scalability and performance characteristics!

;^)
I am currently creating a website for the allocator where you will be able
to download a copy under a restrictive non-commercial license and experiment
with it all you want. Of course, commercial license agreements can be worked
out if you think this thing is worth integrating with some of your
existing/future commercial software suites...

Finally, I can basically prove that memory allocation can scale to many
thousands of cores, and many more indeed!
Take a look at the code and tell me what you think! Well, perhaps we should
move further discussions over on comp.programming.threads where is more on
"topic"...
Any thoughts/criticisms/suggestions on the invention?

Thank you all for your time!
:^)


Chris Thomasson
--------------

http://appcore.home.comcast.net/
(extremely scaleable lock-free abstractions for Intel-ASM/C/C++)

http://appcore.home.comcast.net/vzoom/refcount/
http://appcore.home.comcast.net/vzdo...c/static-init/
(mostly lock-free atomic reference counting)

http://appcore.home.comcast.net/vzoom/round-1.pdf
http://appcore.home.comcast.net/vzoom/round-2.pdf
(scalability concerns anybody!?)
enjoy! ;^)


Any thoughts?
Jan 30 '07 #8
Chris Dollin wrote:
CBFalconer wrote:
>Raman wrote:
>>Chris Dollin <chris.dol...@hp.comwrote:
Raman wrote:

Can any one tell me how to implement malloc.

There's an example in K&R. What's wrong with the one you've got?

Actually I Got this question in A Interview .

You can't, and be portable.

You're thinking of alignment?

(I'm thinking of a large static array.)
That's good enough for a test bed. You also have to worry about
performing arithmetic with pointers, depending on the design.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
Jan 30 '07 #9
Chris Thomasson wrote:
Seriously, my invention is actually one of the fastest atomically
thread-safe virtually zero-overhead memory allocators currently out there.
It beats the pants off HOARD and runs circles around Maged Michael's
so-called lock-free memory allocator...
Go back to comp.programming.threads please. There's only one newsgroup large
enough to take your constant "appcore" RFCs.
Jan 31 '07 #10
"Christopher Layne" <cl****@com.anodizedwrote in message
news:11************@news-west.n...
Chris Thomasson wrote:
>Seriously, my invention is actually one of the fastest atomically
thread-safe virtually zero-overhead memory allocators currently out
there.
It beats the pants off HOARD and runs circles around Maged Michael's
so-called lock-free memory allocator...

Go back to comp.programming.threads please.
10-4!
Feb 2 '07 #11

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

Similar topics

5
by: Ruslan Vorobey | last post by:
Hi All. Does anybody saw any C++ new operator implementations? I need just to know does it use malloc? Especially I interesting about standard C++ libs implementation under AIX 5.1L. Thank...
12
by: Anil | last post by:
Hi, Where can I get the source code that has the implementation of the below C operators/functions: malloc sizeof new strcmp strtok
8
by: farhanb | last post by:
hello, I am writing a simple linked list implementation. When I use function insert1 I must allocate to head in my main to get it to work otherwise list stays empty but when I use function...
110
by: Gregory Pietsch | last post by:
I'm writing a portable implementation of the C standard library for http://www.clc-wiki.net and I was wondering if someone could check the functions in math.h for sanity/portability/whatever. I'm...
49
by: Karsten Jung | last post by:
Hello together, We have to make our own implementation of malloc() under Linux. Does anybody can give me a hint where to start? Our implementation should only work under Linux. Thanks ...
41
by: jacob navia | last post by:
In the C tutorial for lcc-win32, I have a small chapter about a debugging implementation of malloc. Here is the code, and the explanations that go with it. I would appreciate your feedback...
52
by: ¬a\\/b | last post by:
is it possible that a malloc function that use a nobody student is better than all yours :) How many errors do you see? Bug1: memory<13MB Bug2: it seems do you have to write you own sprintf...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
27
by: Kislay | last post by:
How is realloc implemented internally ? If there is not enough memory in place to allocate , is new memory allocated somewhere else and the 2 regions linked via a pointer , OR , is the old region...
3
by: C++Liliput | last post by:
Hi, I was looking at the implementation of operator new and operator new in gcc source code and found that the implementation is exactly the same. The only difference is that the size_t argument...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
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
agi2029
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,...
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.