Click here to Skip to main content
14,384,743 members

C / C++ / MFC

 
QuestionPROGRAMMER'S MOM- Needs your help =) Pin
Member 1465597214-Nov-19 8:57
memberMember 1465597214-Nov-19 8:57 
AnswerRe: PROGRAMMER'S MOM- Needs your help =) Pin
OriginalGriff14-Nov-19 8:59
protectorOriginalGriff14-Nov-19 8:59 
Questionpassword in star form Pin
Member 1461560312-Nov-19 0:34
memberMember 1461560312-Nov-19 0:34 
AnswerRe: password in star form Pin
CPallini12-Nov-19 1:33
mveCPallini12-Nov-19 1:33 
SuggestionRe: password in star form Pin
David Crow12-Nov-19 6:48
memberDavid Crow12-Nov-19 6:48 
AnswerRe: password in star form Pin
Stefan_Lang12-Nov-19 22:07
memberStefan_Lang12-Nov-19 22:07 
QuestionHow to make the heap address(by new) have the same every time the program runs? Pin
Member 1308136910-Nov-19 16:36
memberMember 1308136910-Nov-19 16:36 
AnswerRe: How to make the heap address(by new) have the same every time the program runs? Pin
k505410-Nov-19 17:19
memberk505410-Nov-19 17:19 
There's no mechanism within C++ to do that. In fact, modern run time systems are designed so that program data spaces are different for each program invocation. For example:
$ cat example.c
#include <stdio.h>

int main()
{
    int n;
    printf("&n = %p\n" , &n);
}
$ for ((i=0;i<4;++i)); do ./example; done
&n = 0x7fff2ddda67c
&n = 0x7ffdece1243c
&n = 0x7ffe42e7d2bc
&n = 0x7fffd2e78b2c
$
Note that even this simple program gives different addresses for the address of int n on successive runs. This is to make it difficult for any malicious program to interfere with and modify a running program, or to predict where a program will place data.

Also note that in any modern OS (outside of some embeded applications), you are dealing with virtual addresses anyway, so where your process thinks an object is and where the object actually is in physical memory are completely different, so you need to know things like the value page frames and things to work out a physical address of an object in memory.

Outside of some sort of educational value, I can't see any up side to always getting the same address when calling new, so maybe you might want to think about why you want this behavior and come up with a new plan.
GeneralRe: How to make the heap address(by new) have the same every time the program runs? Pin
Member 1308136920-Nov-19 16:48
memberMember 1308136920-Nov-19 16:48 
AnswerRe: How to make the heap address(by new) have the same every time the program runs? Pin
CPallini11-Nov-19 23:10
mveCPallini11-Nov-19 23:10 
GeneralRe: How to make the heap address(by new) have the same every time the program runs? Pin
Member 1308136920-Nov-19 16:49
memberMember 1308136920-Nov-19 16:49 
QuestionRe: How to make the heap address(by new) have the same every time the program runs? Pin
David Crow12-Nov-19 6:46
memberDavid Crow12-Nov-19 6:46 
AnswerRe: How to make the heap address(by new) have the same every time the program runs? Pin
Member 1308136920-Nov-19 16:56
memberMember 1308136920-Nov-19 16:56 
AnswerRe: How to make the heap address(by new) have the same every time the program runs? Pin
leon de boer13-Nov-19 3:34
memberleon de boer13-Nov-19 3:34 
GeneralRe: How to make the heap address(by new) have the same every time the program runs? Pin
Richard MacCutchan13-Nov-19 6:01
protectorRichard MacCutchan13-Nov-19 6:01 
QuestionCTreeCtrl item images without CImageList ? Pin
Maximilien30-Oct-19 9:32
memberMaximilien30-Oct-19 9:32 
AnswerRe: CTreeCtrl item images without CImageList ? Pin
Richard MacCutchan30-Oct-19 10:42
protectorRichard MacCutchan30-Oct-19 10:42 
GeneralRe: CTreeCtrl item images without CImageList ? Pin
Maximilien30-Oct-19 13:04
memberMaximilien30-Oct-19 13:04 
QuestionFTPS Connection Pin
Paul201324-Oct-19 11:28
memberPaul201324-Oct-19 11:28 
QuestionRe: FTPS Connection Pin
David Crow29-Oct-19 10:10
memberDavid Crow29-Oct-19 10:10 
AnswerRe: FTPS Connection Pin
Paul201330-Oct-19 9:25
memberPaul201330-Oct-19 9:25 
QuestionRe: FTPS Connection Pin
David Crow30-Oct-19 11:17
memberDavid Crow30-Oct-19 11:17 
AnswerRe: FTPS Connection Pin
Paul201330-Oct-19 12:30
memberPaul201330-Oct-19 12:30 
Question.bmp and .ico MFC vc++ Pin
Member 1457555624-Oct-19 3:21
memberMember 1457555624-Oct-19 3:21 
QuestionRe: .bmp and .ico MFC vc++ Pin
David Crow24-Oct-19 3:41
memberDavid Crow24-Oct-19 3:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.