473,327 Members | 2,069 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,327 software developers and data experts.

How to store data at a given location

Hi
How do I store data at a given memory location? For eg: I want to store 25 at location 1000. How do I do it? I tried using placement new(). But it is giving segmentation fault during runtime.

Thanks
Mar 21 '08 #1
7 2882
weaknessforcats
9,208 Expert Mod 8TB
You can't store at locartion 1000 becuse that is outside your process address space.

You can use placement new to store at a named address only if that address is in your process address space.
Mar 21 '08 #2
whodgson
542 512MB
Pending googling 'process address space' which appears to be ahead of RAM and finding out how your machine allocates it--- if it does? You could store your data in a vector and then get its first element address using &. Then instruct the program to store the data at that location which would be superfluous and of questionable ethics but it could be proved by a later address query that it is the appropriate address. I omit QED for reasons of modesty.
Mar 23 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
You could store your data in a vector and then get its first element address using &. Then instruct the program to store the data at that location which would be superfluous and of questionable ethics but it could be proved by a later address query that it is the appropriate address.
Questionable indeed. That's not how to implement a private heap.

The OS provides the correct calls. For Windows, you start with CreateProcessHeap().
Mar 23 '08 #4
Hi
My question is I want to store data at a given location (inside address space). Is it possible? Placement new store data at predefined location. Programmer cannot specify the location. Is there any other way?

Thanks
Mar 25 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
Of course the programmer can specify the location:
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     int buffer[1000];         //4000 bytes
  4.  
  5.     char* str = new (buffer)char[100];
  6.     char* str1 = new (buffer+100)char[25];
  7. }
  8.  
Of course, it's your problem to manage the memory buffer.
Mar 25 '08 #6
It is not possible using c ...we can do this with embedded c ...
Mar 26 '08 #7
weaknessforcats
9,208 Expert Mod 8TB
Of course you can do this in C.

Just don't use malloc(). It uses the CRT heap.

You can write your own memory manager.
Mar 26 '08 #8

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

Similar topics

2
by: saurabh | last post by:
Hi All, I want to store the processed salary information in the data base. My requirement is as follows: 1.For each location for an employee , I have to pay/deduct different components (at...
10
by: Ashish | last post by:
Hi I am new to C I have one query.... can i store a value on a given memory location in C say for example i want to store an integer value 10 at location 0X100000. how can i do it in C... if...
10
by: Paul Cheetham | last post by:
Hi, I am developing an application that needs to store some machine-specific settings. The application is going to be published on the network in order to keep the clients on the latest version....
7
by: thisismyidentity | last post by:
Hi all, I am trying to predict the behaviour of floating point load and store operations on integer locations. I ve written a small piece of code having some inline assembly code which I am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.