C++ :: Reading Memory In A Pointer

Aug 3, 2013

I am having a problem with a small exercise program. The program works the first time through the loop but not the second. It faults on this line:

cin >> *(pint + i1);, with this error: pint <Unable to read memory>.

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int MAX(5);
int count(4);
int value(MAX);

[Code] ....

View 5 Replies


ADVERTISEMENT

C :: Reading RAM Memory Directly

Mar 27, 2014

Is there any way to read RAM memory directly. For say i want to access memory location 0x0100 to 0x120. How to do that. how to declare the variable, is it unsigned int. what is the type of read values it hex or ascii. how t cast it.

View 2 Replies View Related

C++ :: Not Allocating Enough Memory To Pointer?

Jan 24, 2014

I wrote the following C++ constructor, and I get an error - BUFFER too small on strcpy_s

Trace::Trace(const char *str) {
if (str) {
int len = strlen(str);
this->m_name = new char[len+1]; // asking for 'len+1' memory elements of char
strcpy_s(m_name, len, str); // **** I get here an error "BUFFER TOO SMALL" ****

[Code] .....

m_name is a private data member of type char* .

View 3 Replies View Related

C++ ::  How To Store Memory Address In A Pointer

Apr 29, 2013

What I'm trying to do is:

int *p;
someType memoryLocation;
cout<<"Enter your memory location: ";
cin >> memoryLocation;
p = memoryLocation;
cout << *p;

I was just messing around with some code, and was curious to if this was possible.

View 6 Replies View Related

C++ :: Pointer To Memory At Offset And Length

Aug 26, 2013

I'm working with memory mapped files and I have a block of memory that I've mapped to.

I want to write a function that returns a pointer to a portion of the mapped memory at an offset and length so I can write to it. I've never worked with memory at this level, is what I'm attempting possible?

I know that mapping functions can map to a part of the file at length and offset but I'm not sure if I should make multiple calls to map the memory from the file or just map the memory once and work with the portions I'm interested in using my proposed GetMemory function.

Code:

LPVOID m_lpData;
LPVOID GetMemory(DWORD pos, DWORD length) {
BYTE* buffer = (BYTE*)m_lpData;
buffer += pos;
// how to get a length of the memory?
return ((LPVOID)buffer);
}

View 14 Replies View Related

C :: Reading Data From CSV File Or Memory Onto Screen?

Jul 26, 2014

I have a csv file (comma delimited text file really) and I have data ,about 6400 lines, and I need to read and display data from 1 line. At the bottom is sample data from my csv file.

I want to read onto the screen the 3rd item .. ie Test User 1 and the date and time at the end (the last 2 items).

I will enter in a number .. from which I will want to retrieve the appropriate record .. in this case I would enter in 514, 563 or 874 and get back the info for that record.

This is a DOS 16 bit application .. and I know that some of the data is in memory already but I am not sure how to tell .. or how to retrieve it.

I do have the ability to save the data to the file at any time .. so I can use that to ensure that the data is current in the text file before I retrieve the data from this 1 row.

I think that it may just be easier to get from the text file ? but I am not sure.

0000,7,0,"Test User 1",53c145cb,db,5,514,514,2014/07/12,10:27:23
0001,7,0,"Test User 2",53d7f,1903,10,563,563,2014/07/24,11:04:31
0002,7,0,"Test User 3",529c,5ffb03,0,874,874,2013/12/02,09:07:58

I am a database guy .. and I am just a bit lost when it comes to C programming as such.

View 9 Replies View Related

C :: Malloc Is Used To Allocate Free Memory To A Pointer

Nov 5, 2014

There is a part in the lesson that explains how malloc is used to allocate free memory to a pointer and gives us 2 examples:

Code:

float *ptr = malloc( sizeof(*ptr) ); and Code: float *ptr;
ptr = malloc( sizeof(*ptr) );

From my logic in the first case we allocate the memory to *ptr and in the second to ptr.

It's a bit confusing, am I missing something?

View 14 Replies View Related

C++ :: Integer Pointer - Get Address Without Allocating Memory

Jun 3, 2013

I have an integer pointer and i want its address without allocating memory,

main() {
int *a;
cout<<a;
}

This is giving 00000000 and its but obvious. Now if i use address of a (&a) along with *a,

main() {
int *a;
cout<<a;
cout<<&a;
}

'cout<<a' gives me a constant address but 'cout<<&a' gives me different address.

what is the reason behind & and why behaviour of 'cout<<a' changes when using with &.

View 8 Replies View Related

C++ :: Does Realloc To Smaller Memory Result In Same Pointer

Aug 10, 2014

If I do this:
void* testPtr = malloc ( 1000 )

And then this:
testPtr = realloc ( testPtr, 500 )

Will the realloc just reduce the allocated size and keep the same pointer, or can there be a chance of it finding another place for that allocation ( Meaning that it will expensively move the memory to another location )?

I am trying to create efficient programs by making my dynamic allocations the least resource hungry as possible during runtime.

View 2 Replies View Related

C++ :: Pointer Incrementing Using Dynamic Memory Allocation?

Feb 13, 2013

I am using a pair of pthreads that call a pair of functions for ping-pong dma data transfer that are used in a loop for data transfer from an acquisition board. For a large # of waveforms, I ultimately run out of PC memory and the program stops. At the end of each function I use the delete[] command to clear memory for reuse, but the pointer appears to advance by the array size used for the transfer until the location exceeds the 2 GB I have for memory. I can see this happening using the Task Manager performance button time plot and window of total memory used continuing to increase to the limit. The culprit for one of the functions (2nd) is:

unsigned char* dataBuffer2 = (unsigned char *) (pci_buffer2.UserAddr);

where pci_buffer1 and 2 have been set up and allocated in main. I also had the following line in each function process:

double* Rin = new double[length];

and it used up memory twice as fast. When I transferred the last line to an area just prior to main and used a constant 1024 for length, the program ran twice as far before exceeding system memory, so it appears that both lines were forcing new memory assignments and moving the pointers accordingly. In addition to using the delete[] command to free memory unsucessfuly at the end of each function procedure, I ended up closing the memory at the end of each procedure, then reallocating it again with the idea that the pointer would be set back to the original value, but it still seems to icrement along. So, neither approach appears to allow reuse of the memory because the pointer continues to march along. Using Visual C++ 6.0 to compile.

View 1 Replies View Related

C++ :: Shallow Copy Of A COM Pointer (memory Leak)

Aug 25, 2012

Code:

HRESULT CAllocMeshHierarchy::CreateMeshContainer(PCTSTR Name,
const D3DXMESHDATA* pMeshData, const D3DXMATERIAL* pMaterials,
const D3DXEFFECTINSTANCE* pEffectInstances, DWORD NumMaterials,
const DWORD *pAdjacency, ID3DXSkinInfo* pSkinInfo,
D3DXMESHCONTAINER** ppNewMeshContainer

[Code] ....

When I make a shallow copy of pMeshData to OriginalMesh (for static mesh rendering, 2 objects pointing to one COM interface), memory leaks start to occur.When I don't, everything is fine.How to solve it? I addref() to it once (with pMeshData) and ReleaseCOM it in destroyMeshContainer

Remarks **** MeshData.pMesh is 0x00000000 while OriginalMesh is a pointer of some value whose values are 0xfeeefeee

View 1 Replies View Related

C++ :: Memory Allocation With Sprintf And Strcat For Reading 1-Wire Device

Mar 9, 2012

I'm using a uC to read the device ID from a One Wire device. I'm trying to have the ID read every second and output to over a USART serial stream for debugging, however I'm having a number of problems getting this to work correctly and I think it has to do with my misunderstanding of memory allocation in this case.

The problem is that when I upload the binary to the uC, it gets the device ID correctly the first time, and from thereafter the program is unstable and starts returning garbage (1st screenshot).

Ideally everything inside of the while loop would be inside of its own function, however I have had nothing but trouble doing that. In fact, when I put that all into it's own function that returns void and takes BUSES as an input, the correct data comes out the first and therefore it somehow exits the "while" loop and never gets back in (2nd screenshot). Another thing I noticed is that when I put the variable declaration outside of the while loop in the code below, I get the same behavior.

I haven't include the code for OWI_DetectPresence and OWI_SendByte ... I've hooked up an oscilloscope and have visually confirmed they are working correctly. Once the OWI_ROM_READ byte is sent over the bus the slave responds with it's device ID. I feel like my issue here is memory allocation and not hardware.

how to fix the issue with the output to USART and how to make this into a function that returns the string of the hex ID?

Code:

int main(void) {
unsigned char OWI_on_bus = FALSE;
// initialize UART for debugging
Init_USART();

[Code].....

View 2 Replies View Related

C++ :: Vector Of Int Class - How To Delete Pointer X In Destructor To Free Memory

Feb 25, 2015

An attempt to create a class which is basically a mimic of vector<int> i don't seem to know how to delete pointer x in a destructor to free memory, also on pushback and pushfront methods, i can't free y when i implement delete[] y; y=NULL; i get some NULL out put when cout 'ing the object in main, why is that happening and how do i free memory y.

#include<iostream>
using namespace std;
class vectorOfint{
int* x;
int size;
public:
vectorOfint();

[Code] .....

View 6 Replies View Related

C++ :: Virtual Function Table Pointer Misplaced In Object Memory

Jul 29, 2014

I have found that when I dump a C++ object from memory to a file - it seems that there is a misplacement of the last Virtual-Function-Table pointer - in that appears at the beginning. The result is that the gdump information based on this object dump (using green hills) is incorrect. I copied the contents of the gdump information below. The executable is compiled in linux.

Basically MEIO::CameraStatus contains an item that relates to its parent class (line 188). Then it has 18 items that are all Diagnostics::EventsCounter items. Now for each Diagnostics::EventsCounter item there is a Virtual-Function-Table Info Pointer as its last item. All is fine and good except that the last item of MEIO::CameraStatus which is _selfReset is missing its last item of 4 bytes (which is the Virtual-Function-Table Info Pointer ). On the other hand - right before the first Diagnostics::EventsCounter item ("_vidErrors") - there is an extra 4 bytes which happens to be the Virtual-Function-Table Info Pointer. As I said the gdump information file does not see this.

Why the object memory "moves" the last Virtual-Function-Table Info Pointer to the beginning (right before _vidErrors) and is there a way to "fix" this?

///////////////////////////////////////////////////////////////////////////
"MEIO::CameraStatus" val:0x000002f0 ind208,-1) Struct-Begin Info
188: "" offset 0, Parent-Class Private Info C++ Struct ref = 114
189: "_vidErrors" offset 160, Member Info C++ Struct ref = 128
190: "_vdiErrors" offset 480, Member Info C++ Struct ref = 128

[Code] .....

View 4 Replies View Related

C :: Keep Track Of Size Of Blocks Of Memory That A Pointer Points To - Malloc Is Stuck On 8

Jan 8, 2014

I'm trying to keep track of the size of blocks of memory that a pointer points to. No matter what I do, this code below always outputs the integer 8.

If I change 1000 to 5, I still get 8. If I change it to 0, I get 8... If I change it to -1, I get 8. If I change int *a to double *a, I get 8. If I take away the & symbol, I get 8. If I use *& instead, I get 8.

Why? I want it to output 1000. If I change that to 500, I want it to output 500.

int *a;
a = malloc(1000 * sizeof(int));

int j = sizeof(&a);
printf("%d", j);

I want to build my skills where I can allocate, inspect and change memory sizes.

View 4 Replies View Related

C :: Pointer Variable Indicating Memory Location - Volatile Type Qualifier

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

C :: Reading Words Into Double Pointer?

Apr 22, 2013

I have a double pointer, and I need to read words into it. Here's what I have so far:

Code:

while(fscanf(keywordFile,"%s",keyinputter)==1){
keys_cnt++;
}
keywords = (char**)calloc(keys_cnt,sizeof(char));

[Code]....

keyinputter is an array of size 30. The first while loop finds the number of words in a file so that I can calloc the correct amount of space for the double pointer, keywords. The second while loop is supposed to read the words into the double pointer, but when I run a print statement to print the string at keywords[0], it only prints null and not the word. Am I assigning the strings to the double pointer in the wrong way?

View 4 Replies View Related

C/C++ :: Reading From File To Construct A Pointer Based Maze?

Nov 29, 2014

I'm trying to read a "pointer-based" maze .txt. The first letter in each row corresponds to the room letter...then the letters that follow are North node, East node, South node, and West node respectively. The asterisk indicates an empty room or not a valid option.

Here is what I have come up with, what is happening is after the file is parsed by read_maze it is calling my is_empty function indicating that there is no maze because it doesn't go into the else statement here.

I've attached a sample input file:

 maze.txt (130bytes)
Number of downloads: 19

We can't assume the rooms will be in order alphabetically A - Z, We are expecting a maximum of 12 rooms and there is a space between each letter or asterisk.

void Maze::read_maze(string FileName){

string line;
ifstream inStream;
inStream.open(FileName.c_str());
int test = inStream.peek();
int i = 0;
if (!(inStream.fail())){
while (!inStream.eof() && test != EOF){

[code]....

View 5 Replies View Related

C++ :: Linked List Node Passed As Parameter / Argument Pointer To Pointer Notation

Jan 17, 2014

I was having problems changing the value of my head node I passed it as an argument as head which would be the address. The parameter was defined as struct node *head. like this

bool deleteNode(struct node *head, struct node *delptr)

I tried manipultaing pointer values to change head node value but it did not work. I saw some code online which used pointer to pointers(in code below) to change head node value it worked I dont fully understand why. Would like better understanding of why.

Would also like to know why the argument call needed &head instead of just head.

remove = deleteNode(&head,found); opposed to remove = deleteNode(head,found);

#include "stdafx.h"
#include<iostream>
struct node{

[Code].....

View 1 Replies View Related

C++ :: Calling Defined Function Pointer From Another Pointer To Class Object?

Aug 19, 2014

I am attempting to implement function pointers and I am having a bit of a problem.

See the code example below; what I want to be able to do is call a function pointer from another pointer.

I'll admit that I may not be explaining this 100% correct but I am trying to implement the code inside the main function below.

class MainObject;
class SecondaryObject;
class SecondaryObject {
public:

[Code]....

View 10 Replies View Related

C :: Print Pascal Triangle And Stores It In A Pointer To A Pointer

Nov 27, 2013

I have to write a program to print pascals triangle and stores it in a pointer to a pointer , which I am not entirely sure how to do. I also have to write the file and read it, then create a binary file. Assignment is attached. I am not the best with programming and especially with pointers. I will post my code below.

Code:
#include <stdio.h>
#include <stdlib.h>
void writePascalTriangle(char *fileName, int heightOfTriangle, int **triangle) {
FILE *fp;
fp=fopen("writePascalTriangle.txt", "w");

[Code] ....

View 4 Replies View Related

C++ :: Get Pointer That Iterator Points To And Store In Pointer Variable?

Apr 19, 2014

I'm making a system like twitter for class called ShoutOut.com I want to be able to get the PublicShoutOut pointer pointed to by the start iterator and assign it to firstShoutOutToDisplay and secondShoutOutToDisplay because I need that in order to pass the pointers to one of my functions. When I step through the debugger the values in start are all default values like "" and so are the values in this->firstShoutOutToDisplay but the message that start points to is being output just fine.

EDIT: got rid of irrelevant code. Am I using the correct syntax to do this?

if (start != finish) {
//getting these because a shoutout needs to be passed to the function that displays
//options for a shoutout
this->firstShoutoutToDisplay = (*start);

[Code] ....

View 2 Replies View Related

C++ :: How To Convert Void Pointer To Int / Double / String Pointer

Mar 7, 2013

I have a function:

const void insertStuff(const void *key, const int value){
// I want to convert the void pointer into one
// of three types of pointers(int, string, or double)
switch(value){
case 0:
int *intPtr = key;

[Code] .....

But this causes an error of: "crosses initialization of int*intPtr"

What's the correct way of implementing this?

View 1 Replies View Related

C :: Access Element Of Array Through A Pointer To A Pointer

Dec 25, 2013

i have been fiddling with pointers but I don't understand how the proper syntax is written when I want to acces an element of an array through a pointer to a pointer...The code is all mostly just random bs for learning purposes. I marked the problem "// THIS LINE"

Code:

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#define MAX_DATA 100
int find_average(char *iden, ...) {

[Code]...

View 2 Replies View Related

C :: How To Declare Two Dimensional Array Using A Pointer To A Pointer

Jul 16, 2013

This is a sample program that declares a Matrix as a structure with an array as a pointer to a pointer. The following program is supposed to store a matrix in the structure "_Matrix" and later print the matrix just entered but it fails giving me a "segmentation fault". The sample code is given below

Code:
#include <stdio.h>
#include <stdlib.h>
struct _Matrix {
int row_size;
int col_size;
int **mat;

[Code] ......

View 1 Replies View Related

C++ :: Pass Matrix By Reference Using Pointer Of Pointer

Jun 20, 2014

i really don't know why has a error in my code, that pass a pointer of pointer (name of a matrix with 2 dimensions). Here is the source code of a simple example where appears segmentation fault when execute (but compiles normal):

#include <stdio.h>
#define LINHAS 3
#define COLUNAS 5
float a[LINHAS][COLUNAS];
void zeros(float **p,float m, float n){
int i,j;
for(i=0;i<m;i++)

[Code]...

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved