C :: Mixed-type Contiguous Memory Buffer
Mar 1, 2014
I'm writing a program that communicates with another program over TCP/IP. I need to assemble contiguous buffers of mixed data to send to the server. For example, one of the messages must contain multiple 32-bit integers and 64-bit floats, each in its own appropriate field. I also need to receive and decode similar buffers.
The Windows TCP function "send(socket s,char *buf, int len, flags)" takes a pointer to a character array to send. Likewise, the TCP function "recv(socket s,char *buf,int len,flags)" takes a pointer to a character array to fill. I've tried creating structures describing the send and receive messages, with the fields appropriately laid out. But the CODE::BLOCKS compiler complains when I try to hand send and recv the pointers to the structure variables. Am I on the right track, or is there a better way to do this?
View 2 Replies
ADVERTISEMENT
Jan 20, 2014
I have a C program. Within it, I would like to embed either a file or a pre-assigned variable. I would prefer a method that is platform independent.
I am using the data type "RSA" from <openssl/rsa.h>. I have a key file in PEM format, but I would like to embed an RSA object in the program instead. I tried creating a char array and then casting the pointer, but that caused some sort of illegal casting issue. I tried using memcpy but I haven't been able to get it working that way. What is the best way of going about this? Is it possible to read a file directly from a memory buffer?
View 1 Replies
View Related
Dec 24, 2014
I am trying to add some functionality to this project: [URL] ...
Under this [URL] ...
This latest comment based on;
host.data = (u_char *) "112.168.231.19:80";
for (i = 0; i < peer->name.len; i++) {
peer->name.data[i] = host.data[i];
}
or more simpler:
peer->name.data = host.data;
States: "Because strings always require an extra memory buffer (and the burden of memory management) while primitive values like booleans and numbers don't."
Which makes sense since a boolean change (down/up) does actually changes a runtime value, however the string replacement shows via '/upstreams' that the value has changed but at runtime it is still using the old value.
So in short it looks like I do need a buffer to change the string value.
My question is why? if 'peer->down' works on a memory fragment where its value resides then why doesn't a 'peer->name.data = host.data' do the same thing? can this be done without a buffer? once you allocate memory and store host.data in to this where do I copy it to?
View 5 Replies
View Related
Jan 27, 2014
I have a data buffer project in Windows 7 x64 embedded OS (using Visual Studio 2008), that would work simply like that:
One writer application will send data (no network protocols, just procedure call on the same machine) to my app like 20 packages per second, each data packages will be approximately 3 MB size and comes with a timestamp tag.
My application will store each data item for 100 minutes and then remove. (So I can calculate the total size from beginnig no need for dynamic allocation etc...)
Meanwhile there will be up to 5 reader applications which will query data from my app via Timestamp tag and retreive data (no updates or deletitions on data by reader apps).
So since the data in my buffer app can grow over 50GB I don't think that shared memory is going to work for my case.
I'm thinking about using Boost Memory Mapped Files or Windows API Memory Mapped Files.
So theoratically I will crate a fixed size File on harddisk (lets say 50GB) and then map some portion to RAM write the data to this portion, if the reader applications wants to use the data which is mapped currently on memory, then they will use directly, otherwise they will map some other potion of the file to their address spaces and use from there...
My problem is I haven't use Map File concept at all and I'm not a C++ developer so I'm not very familiar with the language fundementals. I've searched tutorials of boost and msdn for windows as well but there is not too much code example.
So I don't know how to map some portion of the data to memory and manage it, also how to search data in file or memory according to the timestamp tag. Yes there are codes for creating files and mapping the whole file to memory but none for dividing it into regions, aligning or padding the data which I need for my case.
View 2 Replies
View Related
Sep 18, 2014
I'm searching a program that can detect a special type of memory leaks, like these:
int a = 12;
char c[10];
char cc = c[a];
View 8 Replies
View Related
May 12, 2014
If I have number of arrays (its 3 for instance) with fixed size (15), it consist of zeros and non-zeros
eg:array1[15]={5,5,0,0,4,4,4,0,0,0,1,0,0,0,3}
array2[15]={1,0,0,0,0,7,7,0,0,3,0,0,0,0,2}
array3[15]={6,6,6,0,8,8,8,0,0,0,3,3,0,0,4}
...........
sample output for the above arrays:
Index Nim_of_zeros
3 1
7 2
12 2
How can I count the common zero sequences and there indexes of arrays?
View 2 Replies
View Related
May 11, 2014
If I have number of arrays(is 3 for instance and may vary) with fixed size (15), it consist of zeros and non-zeros
eg:array1[15]={5,5,0,0,4,4,4,0,0,0,1,0,0,0,3}
array2[15]={1,0,0,0,0,7,7,0,0,3,0,0,0,0,2}
array3[15]={6,6,6,0,8,8,8,0,0,0,3,3,0,0,4}
...........
How can I count the common zero sequences and there indexes for all arrays?
sample output for the above arrays:
Index Nim_of_zeros
3 1
7 2
12 2
View 1 Replies
View Related
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
May 12, 2014
If I have number of arrays(its 3 for instance and may vary) with fixed size (15), it consist of zeros and non-zeros
How to write a program to count the common zero sequences and there indexes of arrays?
eg:array1[15]={5,5,0,0,4,4,4,0,0,0,1,0,0,0,3}
array2[15]={1,0,0,0,0,7,7,0,0,3,0,0,0,0,2}
array3[15]={6,6,6,0,8,8,8,0,0,0,3,3,0,0,4}
...........
sample output for the above arrays:
Index==> Nim_of_zeros
3==> 1
7==> 2
12==> 2
View 2 Replies
View Related
Aug 23, 2013
I have used beep() and sound() functions. But both of them generate sounds of only fixed frequency. Is there any way i can generate a sound of mixed waveforms. I am currently using this code, but it isnt reliable at all times and for all frequencies,
for(i=0;i<500;i++)
{
sound(500);
delay(2);
sound(250);
delay(2);
}
View 19 Replies
View Related
Oct 25, 2014
I should sort an array of mixed float and integer numbers by merge method, and using the pointers to sort that mix array. how to use pointers to sort those different type of data.
View 19 Replies
View Related
Nov 5, 2013
I am required to write a program which, when given an nxn 2D array of char, and the specified coordinates of a specific point in that array, returns thelargest number of horizontal, vertical or diagonal contiguous (side-by-side) sequence of points of that same char value that intersects with the given point.
The way I took on this problem was to:
1) First find out the number of points with the same char value up, down, right, left, north-east, north-west, south-east, and south-west of the given point.
2)Add up+down+1(the one is for the point itself), north-west+south-east+1, etc...
3) Finally I compared the four values (updown, rightleft, NESW, NWSE) and returned the largest one.
Well, that's how the program is supposed to work in theory but as you can probably guess it doesn't work. In addition to telling me what I'm doing wrong, is there a simpler way to do what I am trying to accomplish?
Here's the code:
Code:
int findLongest(char **board, int n, int row, int col)
{
char current;
int rightleft, updown, NESW, NWSE;
int r, c, c1=0, c2=0, c3=0, c4=0, c5=0, c6=0, c7=0, c8=0, d;
int t1=1, t2=1, t3=1, t4=1, t5=1, t6=1, t7=1, t8=1;
current=board[row][col];
//check Above: col remains the same
for(r=row-1;r>=0||t1!=0;r--)
//with the condition r>=0 I made sure not to accidentally check values outside of the array
[Code]...
View 1 Replies
View Related
Feb 22, 2015
1) ask the user to input a mathematical expression in the following format:
NUMBER Operator NUMBER Operator NUMBER
Example: 17 + 15 - 3
Example: 2 * 3 - 4
How to output the answer of the users equation. Is there a function that includes all math operators (+,-,/,*)? Would i need to write each possible scenario using if statements?
View 2 Replies
View Related
Mar 28, 2015
How to properly read data from a .txt file.
If I have data stored in a .txt file, which is formatted/stored like this:
Code:
Apples and Strawberrys
10
Cherrys
12
Pears
16
Grapes, Melons, and Peaches
20
I know that if I read/extract, and print the data like this;
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream dataFile("test.txt");
string textData;
[Code] ....
Each line of data is stored in the string "textData" and printed to the screen, exactly as it was stored in the .txt file. So, all is clear to me up to that point.
But, what if I wanted to store each line of text in the string "textData", and store the numbers/integers into a separate variable called "numberData"? How would I retrieve and store the numbers (in the above example .txt file, every 2nd line) separately from the text?
For now, to keep things simple, let's assume that the data in the .txt file is stored/formatted as in my example (1 line of text, 1 line containing a number/integer, ...repeat) so, there is no need to test if the retrieved data is actually text or an integer, before it is stored in the appropriate variable type.
View 14 Replies
View Related
Jan 18, 2014
I know to read a strings into array and tables.. what is they are mixed up?? strings are just names ( 3 characters) and there are bunch of table.. the max size was set to 60
ex. text file
JES
DAN
JEN
.
.
.
01010101
10010101
RAM
JET
01010010
10100101
.... and so on
should i use a while loop?
View 10 Replies
View Related
Oct 29, 2014
I have an int array of size 5 and I have my program to accept 5 integers between 10 and 100 inclusively. I should be able to type integers over and over again until I get 5 that are in the range, 10 <= x <= 100. Now when I get 5 that fall in that range the program should continue but instead it wants a 6th number before continuing. I'm suspecting the program is hanging on to a new line character. Anyway to ignore the new lines? Couldn't find anything for C# without clearing the screen.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DupElim {
//dup elimination
[code]....
View 5 Replies
View Related
Apr 27, 2013
I'm having some problems with changing an array of numbers of type char to type int. Every time i try to sum 2 array indexed values it returns some letter or symbol. Also, if i change the type of the array in the functions the compiler gives me an error message. I would also like to add that the problem requires that the first two arrays be char so each individual number gets assigned to a different value.
My current code is:
Code:
#include <iostream>
void input(char a[], char b[], int& size_a, int& size_b);
void convert(char a[], int size);
void reverse(char a[], int size);
void add(char a[], char b[], int c[], int size);
int main()
[Code]....
View 4 Replies
View Related
Dec 21, 2013
how to convert an element of int type of an array to char type?
View 2 Replies
View Related
Oct 17, 2014
Im creating a permissions profiler in c by using stat()I ran into a problem of getting a bad address as in my path. Ive tried multiple solutions with no dice, and now I have one more solution I want to try but I dont understand how.how do you use a snprintf and pass that into a buffer, and pass that into a path for stat()?
View 9 Replies
View Related
Jan 12, 2015
I`ve wrote a function for my utility to XOR char* buffer by a key, then to reverse it with the same key. Here is the code, it`s simple enough:
Code:
static inline char* XOR_buffer(const char* d, const char* k ) {
char *newstr = (char*) malloc(sizeof(char)* strlen(d));
newstr[0]='';
printf("%d is size of string
", strlen(d));
char *begin = newstr;
char* ret = begin;
int len = strlen(k);
}
[code]....
The lengh of the string is reduced by the second XOR call. You can try it out, just define XORDBG to view the error message in the second pass to the buffer.
View 9 Replies
View Related
Feb 5, 2014
I want to use a const char* as a buffer. I am reading values from a file and adding them to a buffer. How to extract the values is simple enough. I am reading through a filestream, reading each character into a char pointer and progressing that char pointer every time. I have another char pointer marking the start positon
eg.
char *mychar = new char;
char *char1 = new char;
char *char2 = new char;
const char *constchar ;
char2 = char1;
while(filestream.read(mychar,1) {
*char1 = *mychar;
++char1;
}
Then I get this problem: constchar = mychar; // const char* = char*.
Constchar does not catch all the data in other words. At some stage some data is lost due to zeros in the data.. How can I put values into a const char and get around this problem? The const char* will //only record everything up until the first zero.
View 6 Replies
View Related
Aug 22, 2014
suddenly nothing is written to my file
void taglessLine(char line[],ofstream& buffer){
buffer.open("buffer.txt", ios::out);
int len=strlen(line);
[Code].....
View 2 Replies
View Related
Dec 17, 2014
get some opinions on, or established methods on how your buffer size should be decided.
View 2 Replies
View Related
Oct 10, 2014
I am writing a program and am asking the user to enter a number between 1-12.
If they do not, they will be promoted over and over again to enter a number between 1-12.
However, if the user enters a letter or anything else scanf seems to stop working and then my loop goes out of control.
View 2 Replies
View Related
May 9, 2012
I'm trying to analyze buffer text, but unfortunately i'm not able to do so... My approach
Code:
// here i'm getting and reading text from the user
bzero(buffer, 1024);
read(m_Socket, buffer, 1023);
string inputText;
inputText = string(buffer);
[code]....
View 2 Replies
View Related
Apr 13, 2014
Basically it has to do with the byte ordering in a binary buffer vs the typing of a variable used to hold it.
To give you an example, if I have a buffer (say of indefinite length), and a ptr "ptr" pointing to a byte in the buffer (say, C0), such that if I open the buffer in a binary viewer it reads like this: Code: C0 DD FE 1F Such that this is true:
Code:
/*ptr is uint8_t*/
*ptr == 0xC0
Then I do this:
Code:
uint16_t var;
var = *(ptr+1);
I would expect the result to be:
Code: DD FE /*56830*/
Though if I print that out with:
Code:
printf("%u
", var);
It'll print:
Code: 65245 /*(FE DD)*/
Now obviously it's byte swapped, but what is causing that? I'm assuming if I just stream that out to a file byte by byte it'll be fine, so it's something with the 16 bit data type (also have seen this issue with a 32 bit data type, where all 4 are in reverse order). Is there any way to 'fix' it except bit shifts & masks?
View 14 Replies
View Related