473,614 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

RedSon
5,000 Recognized Expert Expert
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 2112
Savage
1,764 Recognized Expert Top Contributor
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 Recognized Expert Expert
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 Recognized Expert Moderator Expert
Use the WM_COPYDATA message.
Oct 6 '07 #4
RedSon
5,000 Recognized Expert Expert
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
1391
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 applications. It has found use in both the private sector and FSF/GNU applications such as DotGNU. By being open with respect to object and data encapsulation, Goldwater allows client facing data presentation servers to render their output in XML, a...
13
3461
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. Sadly, they chose the wrong middleware platform. Microsoft has notorious application software. They never produce a true enterprise level software. Most of their software products target small companies. However, the strength of C++ is it can...
8
4110
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 source / free middleware packages, that I can use. I have done some searching over the web ( sourceforge,google ) but havent found that many open source implementations for middleware. I have an application that needs to communicate with other...
5
5336
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 if I use C# instead of native (not managed) C++ ? This software could have to manage 100's of simultanous connections. Realist in C# ? Thanks for your advice.
5
2712
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? Thanks in advance. David
17
2633
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 question. I am looking desperately for a way to TRULY scale out SQL server...in the same way that IIS can be scaled out via App Center. The "in the box" solution for SQL Server 2005 scaling out is the DMV. Unfortunately this solution makes...
1
1217
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 data. The first thought is to write a library of routines that do things like, change_address(), or fire_employee() or whatever. Whoops, now we've decided to move to python. I have to write all of that again.
11
3342
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 ways of passing an array. In the following code, fun1(int a1) - same as fun1(int* a1) - where both are of the type passed by reference. Inside this function, another pointer a1 is created whose address &a1 is different from that of the passed...
17
6833
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
8176
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
8120
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8265
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
7047
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
6085
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
5537
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();...
0
4048
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2560
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1705
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.