C :: Variable Memory Location With Ampersand Vs Pmap
Oct 23, 2014
I just started deal with pointers in C, and one stuff confusing me...
Here is simple code:
int main (){
int var1 = 10;
int var2 = 20;
long ms = 10000000;
printf("Address of var1 variable: %p
", &var1 );
[Code] ...
But - when I run pmap - I don't see this addresses there:
Code:
# pmap -x 16496
16496: ./address
Address Kbytes RSS Dirty Mode Mapping
0000000000400000 4 4 0 r-x-- address
0000000000600000 4 4 4 rw--- address
00007f79cf8b8000 1576 260 0 r-x-- libc-2.12.so
00007f79cfa42000 2048 0 0 ----- libc-2.12.so
00007f79cfc42000 16 16 16 r---- libc-2.12.so
I guess - it's is inside stack:
Code:
# cat /proc/16496/maps | grep stack
7fff0d7e5000-7fff0d7fa000 rw-p 00000000 00:00 0 [stack]
But - how I can obtain this variables addreses, to see them with `pmap`? If I put them as "global":
Code: ...
#include <stdlib.h>
#include <sys/types.h>
int var1 = 10;
int var2 = 20;
int millisleep(unsigned ms);
int retpid(void);
[Code] ......
I have odd addresses in result:
Code:
Address of var1 variable: 0x600a94
Address of var2 variable: 0x600a98
View 1 Replies
ADVERTISEMENT
Jun 26, 2014
If I have a pointer variable indicating memory location in which we have stored what user entered and the pointer is of type volatile if the user gives the character 'a' twice , then this character will not be fetched twice from the memory but only when the character is changed???
This is the one meaning of the volatile? the other is that the value will be changed without the program itself change it?
View 4 Replies
View Related
Jul 12, 2013
In the code below. I believe I am returning the memory location of the value I am looking for. How can get the value?
main.cpp
int choice = 0;
PlayerMenu *newPM = new PlayerMenu;
File *file = new File;
// Menu for loading, creating or exiting the game
choice = newPM->menuChoices();
PlayerMenu.cpp
[Code] ....
I am not sure how to deference the value so I can get at the value instead of the memory location.
View 5 Replies
View Related
Jan 11, 2013
Under Microsoft, I use GlobalAlloc and GlobalFree to dynamically allocate and free memory. Intermittently GlobalFree is reporting error 998 (GetLastError() - Invalid access to memory location). I've checked my logs of addresses returned by GlobalAlloc against those being freed by GlobalFree and when the problem occurs the address causing the error has been allocated by GlobalAlloc and has not been freed before since allocation.
I can't reproduce it. Currently I'm checking for error 998 from GlobalFree and ignoring it if it occurs - which is not satisfactory. I have one function (AllocMem) that calls GlobalAlloc and checks for errors and another function (FreeMem) which calls GlobalFree and checks for errors.
My program uses AllocMem and FreeMem everywhere memory is required or freed. AllocMem and FreeMem are in a DLL. The program is heavily threaded and a different thread may call AllocMem to the one that calls FreeMem. I don't believe I've got a race condition etc as all the code in the program containing the AllocMem and FreeMem calls are part of a CriticalSection using the same variable.
What is a possible cause of this error?
View 14 Replies
View Related
Aug 4, 2014
I have a contiguous sequence of section headers in a file (all the data in the file is stored in void * data), where each section header is the same size and has the same fields in the same order. So it's laid out like an array.
I have to:
- Use an offset value and the number of section headers variables to identify the location and length of the section header table (these are hdr.offset and hdr.length respectively).
- The offset value shows the distance between the start of the file and the start of the first section header (so I need a pointer to the start of the first section header)
- Apply a typecast to location of the section header table to process it as an array of section headers.
Here is what I have done, but I am getting a segmentation fault. What am I doing wrong? How do I fix this?
typedef struct {
unsigned int name;
unsigned int type;
} SectionHeader;
[Code] ....
View 1 Replies
View Related
Nov 8, 2013
I am trying to make a function that allows me to allocate memory to a "mem" variable and setting each of its chunk's status to FREE. FREE is defined as 0. Below is my code of the function.
Code:
int allocate(mem *mm, int num_chunks, int chunk_size) {
int i;
mem *temp;
if((mm = (mem *) malloc((num_chunks + 1) * chunk_size)) == NULL){
perror("Failed to Malloc
[code]...
mem; If my function works the way it should, it should print out five 0 because that is how I set them in the function, but this is not the case. I've looked at my function for 2 hours, but I could not figure out any logical error. Now, I think my problem lies with my limited knowledge of pointer arithmetic. On the other hand, when I insert 1000 as the second argument into my function, it gives seg faults, which is not the case for smaller values like 5, 10, 15, etc.
View 6 Replies
View Related
Nov 4, 2013
So, I've made programs like Prime number searchers and such. But the problem is if I use an int or long int variable for the program I am limited by the variable size. I can't search through numbers larger than their memory size. So my question is: Is there a way to allocate memory to a single variable, NOT AN ARRAY, so I can make a variable as many bytes as I want?
View 3 Replies
View Related
Nov 3, 2013
How do you store a variable in memory so that it isn't changed when the program closes? I don't have any experience with this and am just wondering how it is possible. I am creating a program and want it to store your preferences and scores. In a simple program, everything is just reset and I don't want this for my program. How do I store a variable so that it stays the same, but can be changed even when the program is turned off?
View 2 Replies
View Related
Jul 30, 2014
recently I developed a class header only in C++ to deal with byte arrays. Since I developed programs in other languages that had some libraries to dial with byte arrays, I developed one that the syntax is very similar to other languages.
Since I'm not very familiar with memory management, I was concerned about somethings I've read about (ex: memory fragmentation).
Here is a very simple example of my practice:
class ByteArray {
public:
ByteArray(size_t size) {
buffer = (int8_t*)malloc(size);
}
[Code].....
The class is intended to be used as part of comunication protocol in a webserver, byte arrays are created and destroyed a lot. Should I use pools? Is there a better practice? Am I doing everything wrong (laugh)?
For those who wants to see the entire class: [URL]
View 9 Replies
View Related
May 23, 2013
Here's my code, my problem is that it is not sending the keystrokes to the LOG.TXT file I want them to be going to.
1 #include <iostream>
2 using namespace std;
3 #include <windows.h>
4 #include <winuser.h>
5 #include <stdio.h>
6 int save (int key_stroke, char *file);
[Code] ....
View 1 Replies
View Related
Mar 14, 2015
How can i get the Location of an Image used by the ToolStripButton? I need the locaton to detect if the cursor is above the image that i use for the button. I tried it like this:
private void ToolStripButton_MouseHover(object sender, EventArgs e) {
Graphics formGraphics = this.CreateGraphics();
GraphicsUnit graphicsUnit = GraphicsUnit.Point;
RectangleF imageBoundsF = reloadToolStripButton.Image.GetBounds(ref graphicsUnit);
[code].....
The problem is that i have the width and the height but the location is always 0 or x and y are always 0, so how can i do it?
View 2 Replies
View Related
Jun 6, 2012
Any difference between
Code:
class SomeOtherClass;
void foo(SomeOtherClass* p);
And
Code:
void foo(class SomeOtherClass* p);
I was told that "2" would limit the scope of the forward declaration to the declaration of foo... However, after testing it, it appears that both behave the same...
View 3 Replies
View Related
Feb 1, 2014
I recently started learning C++ and wanted to deep a bit into process memory reading for Windows, but I get an error I don't know how to fix. I'm using Visual Studio Express 2013 as my IDE and it tells me this, when I try to run and debug:
"Unhandled exception at 0x77E3E243 (ntdll.dll) in readProcessMemory.exe: 0xC0000005: Access violation reading location 0x00000043."
The Call Stack window says following:
ntdll.dll!_NtRaiseException@12() Unknown
ntdll.dll!_KiUserExceptionDispatcher@8() Unknown
ntdll.dll!_RtlInitUnicodeString@8() Unknown
> readProcessMemory.exe!main() Line 8 C++
[External Code]
And in the Output window is this: First-chance exception at 0x77E3E243 (ntdll.dll) in readProcessMemory.exe: 0xC0000005: Access violation reading location 0x00000043. Unhandled exception at 0x77E3E243 (ntdll.dll) in readProcessMemory.exe: 0xC0000005: Access violation reading location 0x00000043.
My code should be extremely simple, I'm just trying to find a Windows window. But here's the code.
Code:
#include <windows.h>
#include <iostream>
using namespace std;
int main(){
[Code] ......
View 10 Replies
View Related
Aug 19, 2013
I have my libraries in ../../lib location
and when i try to compile :
gcc -O9 -I ../../include/ -L ../../lib/ -o test test.c thr.o -lm -lthread
I get :
gcc: error: thr.o: No such file or directory
obviously the problem is the library path location but my obj is there
ls -al ../../lib/ | grep thr.o
-rw-rw-r-- 1 xxxxxx xxxxxx 23544 Aug 12 23:03 thr.o
????
View 2 Replies
View Related
Aug 16, 2012
I have a 3d Point in space. From this point I have vertices defind by(scale). I have a Quaternion representing the rotation of the object (lets say a block). So...
(1) I know the point in local and world space and can translate.
(2) I know the scale of the object and it's starting vertices intersections at zero rotation.
(3) I have the quaternion which represents the 3d rotation and can translate that to degrees and Eulers.
How do i find the exact points of the vertices after the rotation. (what I'm attempting to do is plot points from vertice to vertice all along the sides/top/bottom of the object.)I have looked at Matrix4 transformations and Quaternions and still do not understand how to find the vertices after rotation.
View 8 Replies
View Related
Oct 21, 2014
I have these two functions listed below. DoEvent() gets called from a window procedure whenever some event occurs. SetEvent() sets an element of the m_Events array a pointer to a Command object to handle the event. The array is zeroed in the constructor.
The error occurs on line 16 in the code in DoEvent(). Why the array is suddenly unreadable. When I call SetEvent() it works just fine, no problem.
When I step through the debugger in SetEvent i see that each element begins as 0 and the element I set is set properly. However, when I step through DoEvent() all elements in m_Events show "?????" "Unable to read memory".
uw::Command* uw::WindowBase::SetEvent(uw::WindowEventsEnum event, uw::Command* command) {
if (event < 0 || event >= FINAL_EVENT_ENTRY)
return NULL;
Command* ret = m_Events[event];
m_Events[event] = command;
return ret;
[Code] ....
View 2 Replies
View Related
Jan 20, 2015
I already wrote:
strncpy(buff2, buff1[i], strlen(buff1)-i );
but this function seem to just copy from the beginning of a buffer to another, not from the ith element.Is there such a function?
Buff1&buff2 are char[10000] and i is declared int, holding the interesting element's position.
View 4 Replies
View Related
May 4, 2013
I have a problem. Im testing character movement in c++ and when i compile and run this, then try to press arrow keys it says "Access violation writing location 0x011feff4.Unhandled exception at 0x770a15de in test.exe: 0xC0000005: Access violation writing location 0x011feff4.The program '[8404] test.exe: Native' has exited with code -1073741819 (0xc0000005)."
#include <iostream>
#include <string>
#include <Windows.h>
#include <conio.h>
using namespace std;
void map1create(); // Function for creating the map1
[code]....
View 2 Replies
View Related
May 19, 2014
I know how to find the occurrences of a character in a string, but I have a more specific problem.
For example, consider the string:
" C 1.3825 4.0000 12.0000 1.9133 0.1853 0.9000 -1.1359 4.0000 "
I want to extract a vector that contains the positions of every first character for each number.
For the example above, the output should be a vector with elements [6 15 23 33 etc...]. These are the positions of the first character for every number.
I need to be able to do this for any arbitrary string with any arbitrary amount of numbers and characters in it (I also need to account for negative numbers).
View 1 Replies
View Related
Mar 5, 2014
Right now my application database is stored in the AppDataRoamingAppName directory.
The client has requested that the administrator choose the location for the database, and have a choice between a local machine, or an online repository.
The clients are not IT people, they are business people, and I don't think it's a good idea to let a user choose where to keep the central app database. Other users (think admin vs user) will need to download the database for use on their own local machines, which is how the issue even came up, it's kind of a shared database that only the admin can add to.
My compromise was to COPY the main database to the location of the user's choosing, then push updates to it as the main database was written to.
So after working on this today, I have the user choose a directory, I add the file path to the application settings, then I create the file and copy the database as needed to the new location (online repositories are next).
View 6 Replies
View Related
Jul 9, 2013
this is my code in c++ and its very simpile but wont compile
#include <iostream>
using namespace std;
int main() {
cout << "Here is some text
";
cout << "Here is a number: ";
[Code] ...
View 1 Replies
View Related
Jan 3, 2013
I have a std::vector of short ints that I need to write to a specific location in a binary file (without using .NET code). To that end, I wrote up this code:
Code:
ofstream fileStream (filePathString, ios::out | ios::binary);
int curPos = 2821;
fileStream.seekp(curPos);
int iter = 0;
while (iter < 1024*1024){
char bytesToWrite[2];
//Low byte
bytesToWrite[0] = LOBYTE(dataVector[iter]);
[Code]...
The code runs without crashing, but when I look at the file afterwards in a hex editor, every byte (even those outside the range I thought I was writing to) are replaced with 00. I suspect I'm missing something in my understanding of file streams. Did I write that code correctly? Seekp does move the pointer over the next byte to be overwritten, yes? Am I getting a memory leak somewhere?
View 5 Replies
View Related
May 28, 2014
I'm trying to make it possible to have a 2 dimensional linked list with syntax like with vectors:
List<List<std::string>> words(5, List<std::string>(5, "Hello"));
I coded everything so that this kind of syntax would be possible, but now, when I execute my program, I get the following error:
#include "stdafx.h"
#include <iostream>
#include "List.h"
[Code].....
View 18 Replies
View Related
Nov 8, 2013
All my code is good, except the functions: findMacLoc and findMinLoc .They don't give me the correct array location of the max/min number in the array.I know is something simple I need to tweak in those two functions.
#include <iostream>
#include <time.h>
using namespace std;
void printArray(int a [], int & size)
{
int i;
for (i = 0; i < size; i++)
cout << a[i] << " ";
[code].....
View 2 Replies
View Related
Mar 5, 2013
I am getting the message Access violation reading location 0xccccccc8. when i try to print my dynamic array during the overloaded << function in my Flight class. where the error happens is surrounded by *s
#include<iostream>
#include<vector>
#include<string>
[Code]....
View 4 Replies
View Related
Feb 2, 2014
I'm having trouble opening a file from a specific location.
#include "maidcafe.h"
....
char directory[80] = {"C:UsersPublicDocumentsAnime NotesTransaction"};
char code[20];
printf("Enter file name");
gets(code);
strcat(directory,code);
system("start "" %s",directory);
i thought this would work, but it didn't xD. I got an error
View 3 Replies
View Related