![]() |
Implement a queue using share memory?
I know how to build a queue in C.
However,what does it mean to "Implement a queue using shared memory?" How to do it? and can someone provide me a start please? thanks in advance! |
Re: Implement a queue using share memory?
I'm not entirely sure, but it might mean that instead of allocating memory on the heap for every node in the queue, that you instead allocate a "pool" of memory for the whole structure and assign memory from there.
For example, if you were writing a linked-list (can you implement a queue with a linked-list? I don't know too much about computer science-y stuff ;)) you might be able to do something like this: :
Alternatively, you could malloc() a block of memory within the structure of the ADT and keep a memory index.EDIT: on second thought, look near the bottom of this page. |
Re: Implement a queue using share memory?
you need to google for "producer consumer problem" or "bounded buffer". you should find what you are looking for.
|
Re: Implement a queue using share memory?
I think you were joking but you can implement a queue a variety of ways lol.
|
Re: Implement a queue using share memory?
if you think i am joking, then you are mistaken. obviously you can implement a queue in many ways. however if you are using memory shared between threads, you must provide protection for that shared resource. this is a classic comp sci problem which is probably what he is currently studying.
|
Re: Implement a queue using share memory?
No, I was talking to Jessehk or whatever his name is. I realize what the problem entails. I also don't understand why anyone would want you to do this in C, and I'm interested to know what kind of practical applications (In C) might use this.
|
Re: Implement a queue using share memory?
fall back son, what language would you want to do this in?
|
Re: Implement a queue using share memory?
Of course you'd want to use C!
C is the language for implementing queues and/or linked lists, since it's basically the only commonly used language that doesn't already support lists or queues. Let's look at TIOBE's list of the most popular programming languages as of May 2008. Source: http://www.tiobe.com/index.php/conte...pci/index.html :
1 Java (Built-in support for queues)Sure you could make your own queue in Java. But it's always more effective to demonstrate something in a language that does not have support for it. That leaves C. So as mbd asked, what language would you use? |
Re: Implement a queue using share memory?
Quote:
|
Re: Implement a queue using share memory?
I think everyone missed the mark here. "shared memory"most commonly means memory shared between processes, not threads. In this case a queue with shared memory could be used to create an interprocess message passing system. You still need to use some kind of semaphore or mutex mapped into shared memory in order to synchronize access to the queue between multiple processes.
You should first learn how to implement a queue, then learn the API for shared memory on your particular OS. Jessehk's code should be able to help you with some of it. |
| All times are GMT -5. The time now is 4:08 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC