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

Middleware needs to pass data to app from heap, how?

RedSon
5,000 Expert 4TB
I'm doing a bit of bluetooth programming and I am writing some middleware to make developing applications easier. The BT driver is implemented as a simple serial driver so its like OpenFile and WriteFile and ReadFile. So I get a notification from the module that there is a phone that wishes to make a hands free profile connection to my device. It also give me a big byte array with some information about the phone that is requesting to connect. So from this point my middleware needs to pass the byte array along to the application for processing. But here is the problem, I can't just pass a pointer to the byte array because as soon as the middleware leaves the function that byte array will be deleted from the stack. So I figured I could make a copy of it in the heap and pass that. But now I run into the issue of who does the deleting of that heap memory? I don't think the application should do it because that kind of defeats the purpose of the middleware, but the middleware can't just delete it willy-nilly because the application might still be using the data. So how do I do it?

The Data path is like this... Message with data comes in from the BT circuit board, it goes to the driver, the driver gives it to the middleware, the middleware needs to give it to the application, the application acts on the data, the application calls into the middleware to respond to the message, the middleware takes the information that the application sent it and makes a BT packet, the middleware passes that response back to the driver and finally the driver sends it out.

Questions? Answers?
Oct 5 '07 #1
4 2085
Savage
1,764 Expert 1GB
I'm doing a bit of bluetooth programming and I am writing some middleware to make developing applications easier. The BT driver is implemented as a simple serial driver so its like OpenFile and WriteFile and ReadFile. So I get a notification from the module that there is a phone that wishes to make a hands free profile connection to my device. It also give me a big byte array with some information about the phone that is requesting to connect. So from this point my middleware needs to pass the byte array along to the application for processing. But here is the problem, I can't just pass a pointer to the byte array because as soon as the middleware leaves the function that byte array will be deleted from the stack. So I figured I could make a copy of it in the heap and pass that. But now I run into the issue of who does the deleting of that heap memory? I don't think the application should do it because that kind of defeats the purpose of the middleware, but the middleware can't just delete it willy-nilly because the application might still be using the data. So how do I do it?

The Data path is like this... Message with data comes in from the BT circuit board, it goes to the driver, the driver gives it to the middleware, the middleware needs to give it to the application, the application acts on the data, the application calls into the middleware to respond to the message, the middleware takes the information that the application sent it and makes a BT packet, the middleware passes that response back to the driver and finally the driver sends it out.

Questions? Answers?
Have you created a class for this?

If so you might try adding a class member that will hold the array.After you have finished all the "dirty jobs" you delete the class(I suppose you will get rid of memory in destructor).

Savage
Oct 5 '07 #2
RedSon
5,000 Expert 4TB
Have you created a class for this?

If so you might try adding a class member that will hold the array.After you have finished all the "dirty jobs" you delete the class(I suppose you will get rid of memory in destructor).

Savage
Thats a good idea, but the problem is that there are over 150 messages that send byte arrays that mean different types. Part of the design decision is to use the windows messaging to post messages to the applications that have subscribed as listeners. Implementing >150 different member fields and structs for this middleware is not considered a valuable activity to pursue.
Oct 5 '07 #3
Banfa
9,065 Expert Mod 8TB
Use the WM_COPYDATA message.
Oct 6 '07 #4
RedSon
5,000 Expert 4TB
Use the WM_COPYDATA message.
Ahh good idea, I forgot about that one. I'll do some more research on it and let you know what happens.
Oct 6 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Guy Blanc | last post by:
http://savannah.gnu.org/projects/goldwater Goldwater is a lightweight distributed middleware, delivering high-performance, high-availability and scalability for successful e-business...
13
by: David Eng | last post by:
Finally, the C++ standard committee realizes the importance of middleware and distributed computing. The committee now focus on C++ extensions for ISO CLI, the Microsoft middleware platform. ...
8
by: Dhanvi | last post by:
Hi Everyone, I am working on an application at my workplace that is a classical example of an applciation that would need middleware to connect various applications.. but I was looking for open...
5
by: Calimero | last post by:
I have to write a middleware that could be see as a very specialized Web server (based on threads and sockets) I hesitate between C++ (speed) and C# (more elegant) What is the performance penalty...
5
by: apm | last post by:
Any and all: Is there an efficient way to pass a large array from .NET to COM? Can references (or pointer) be passed from COM to NET and NET to COM without the object it refers to being copied?...
17
by: IanIpp | last post by:
We have a 3 month old quad processor/dual core server running SQL Server 2005 and already it is getting close to hitting the CPU wall. An 8 way CPU box is prohibitively expensive and out of the...
1
by: tobiah | last post by:
Let's say I want to write a new tool to do something to, or report on people in a database. Each tool is going to have to have all sorts of routines that know about the relationship between the...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
17
by: Daniel | last post by:
When I use the CreateThread API method, what do I need to do when I want to pass more than one parameter where LPVOID lpParameter is passed? Daniel
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.