473,739 Members | 6,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

malloc() implementation

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

Karsten

May 31 '06 #1
49 23175

Karsten Jung wrote:
Hello together,

We have to make our own implementation of malloc() under Linux. Does
anybody can give me a hint where to start?
libc? <www.gnu.org/software/libc/>
Our implementation should only work under Linux.


May 31 '06 #2
Karsten Jung wrote:
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.


Read the glibc code (if "pollution" from LGPL code is not a problem) and
ask on a Linux group, remembering that you will have to write your own
free and realloc code, and you have to deal with the issue of whether
other library routines are calling your malloc or the standard one.
Personally I would not bother without a *very* good reason (which might
exist).

You can't write a malloc routine in standard C which might be part of
why it is in the standard library, hence the suggestion of asking in a
Linux group.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 31 '06 #3
Flash Gordon <sp**@flash-gordon.me.uk> writes:
You can't write a malloc routine in standard C which might be part of
why it is in the standard library, hence the suggestion of asking in a
Linux group.


What you *can* do though is statically allocate a memory buffer, then
allocate out of that with your own "malloc".

--

John Devereux
May 31 '06 #4
Read C Programming Kerninghan & Ritchie you will get the idea.

May 31 '06 #5
Haider wrote:
Read C Programming Kerninghan & Ritchie you will get the idea.


Get the idea about what? Please provide context when responding, there
is no guarantee that people can see the post you are replying to.

In any case, last time I looked I'm sure that K&R did not describe how
to implement malloc which is what the subject line of this thread is..
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 31 '06 #6
John Devereux wrote:
Flash Gordon <sp**@flash-gordon.me.uk> writes:
You can't write a malloc routine in standard C which might be part of
why it is in the standard library, hence the suggestion of asking in a
Linux group.


What you *can* do though is statically allocate a memory buffer, then
allocate out of that with your own "malloc".


True, as long as you call is something other than malloc ;-)
It all depends on what the OP actually wants to achieve.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 31 '06 #7
Flash Gordon said:
Haider wrote:
Read C Programming Kerninghan & Ritchie you will get the idea.


Get the idea about what? Please provide context when responding, there
is no guarantee that people can see the post you are replying to.

In any case, last time I looked I'm sure that K&R did not describe how
to implement malloc which is what the subject line of this thread is..


See Chapter 8, specifically section 8.7.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 31 '06 #8
In article <ju************ @news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.uk> wrote:
Read C Programming Kerninghan & Ritchie you will get the idea.
Get the idea about what? Please provide context when responding, there
is no guarantee that people can see the post you are replying to.
It's a good answer to almost every on-topic question in comp.lang.c,
so the context doesn't matter :-)
In any case, last time I looked I'm sure that K&R did not describe how
to implement malloc which is what the subject line of this thread is..


It describes the implementation of a "rudimentar y" storage allocator
as an example in the section on Address Arithmetic (5.4).

-- Richard
May 31 '06 #9
Richard Tobin wrote:
In article <ju************ @news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.uk> wrote:
Read C Programming Kerninghan & Ritchie you will get the idea.
Get the idea about what? Please provide context when responding, there
is no guarantee that people can see the post you are replying to.


It's a good answer to almost every on-topic question in comp.lang.c,
so the context doesn't matter :-)


The standard and the FAQ are better answers ;-)
In any case, last time I looked I'm sure that K&R did not describe how
to implement malloc which is what the subject line of this thread is..


It describes the implementation of a "rudimentar y" storage allocator
as an example in the section on Address Arithmetic (5.4).


My reply was still technically accurate, I was sure of what I stated. It
just happens that I was wrong to be sure of it ;-)
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 31 '06 #10

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

Similar topics

11
8569
by: Aire | last post by:
On some small-memory systems, is it true that "malloc()" is not supported by the C library? Why is 'dynamic memory allocation' so avoided on such systems? What are major problems of using malloc() here? Thanks!
42
2174
by: Joris Adriaenssens | last post by:
This is my first posting, please excuse me if it is off-topic. I'm learning to program in C. It's been almost ten years I've been programming and a lot of things have changed apparently. I understand from other postings that casting a result from malloc isn't good. In the past I have always been casting the malloc. I think it was even necessary. (But that's a long time ago, I hadn't heard of a standard for C these days). Was it...
36
2275
by: Martin Andert | last post by:
Hello, I have a question regarding malloc and free. Here my code sample: int main() { /* allocating dynamic memory for array */ int* array = (int*) malloc(5 * sizeof(int)); /* ... program code ... */
12
3281
by: gooch | last post by:
I originally posted the following code in a group discussing threads but after further research I think I have a c question about the code. I know there are a couple of non standard c includes here and the POSIX stuff is non standard but this is how I stumbled onto this question. #include <INTEGRITY.h> #include <stdlib.h> #include <stdio.h> #include <pthread.h> #include <signal.h>
21
470
by: ramu | last post by:
Hi, Will the memory allocated by malloc and realloc be contiguous? regards
82
31136
by: quiberon2 | last post by:
Hi, Sorry if it might be a stupid question but what should returns malloc(0) ? void *ptr = malloc(0); I am running gcc 3.3.5 and a non-null address is returned. ( in the compiler that I am currently implementing, NULL is returned. Is it wrong ?)
6
5492
by: sam_cit | last post by:
Hi Everyone, I wanted to know as to how malloc() works, if my understanding is correct, it is implementation specific of the vendor who provides the library(alloc.h). If so, is there any standard as to how it should be implemented? If there is no space in the RAM, will malloc() return NULL or will it allocate a memory in a new page using virtual memory and return the
71
19114
by: desktop | last post by:
I have read in Bjarne Stroustrup that using malloc and free should be avoided in C++ because they deal with uninitialized memory and one should instead use new and delete. But why is that a problem? I cannot see why using malloc instead of new does not give the same result.
10
1905
by: somenath | last post by:
Hi All, I have one question regarding return value cast of malloc. I learned that we should not cast the return value of malloc because it is bug hider. But my question is as mentioned bellow . Lets say I have not included stdlib.h in my program still I am using malloc so compiler will throw warring because with out prototype
8
7265
by: ramsatishv | last post by:
Hi Group, I have one question. If I am allocating memory of 38 bytes to an integer pointer, what will be the memory actually allocated? Will there be any memory alignment concept in malloc? Please let me know the reasons if it is yes / no.
0
8969
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, 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...
0
9479
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, 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...
0
9337
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9266
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,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
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, 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...
1
6754
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.