I was looking through the newsgroup FAQ for an answer to my question,
but it doesn't appear to have one.
I am working with a system that has VERY limited memory. I was
defining two buffers to pass in and out data:
unsigned char inputBuffer[100];
unsigned char outputBuffer[100];
But now it turns out I need the output buffer to be larger under
certain cases. What I wanted to do was make the output buffer double
size:
unsigned char outputBuffer[200];
And then use the input buffer as a portion of outputBuffer:
unsigned char *inputBuffer = outputBuffer + 100;
When necessary, the outputBuffer could then use the large array and
inputBuffer would have it's space as well, without having to allocate
the extra 100 bytes for the outputBuffer.
So I made this change, however, now input is not working. I would
have thought subscripting that was existing in code would still work.
My code all uses inputBuffer[location] as means of accessing the
inputBuffer.
So my question is, what am I doing wrong?
RonB 14 1782
Ron Blancarte wrote On 06/07/07 13:08,:
I was looking through the newsgroup FAQ for an answer to my question,
but it doesn't appear to have one.
I am working with a system that has VERY limited memory. I was
defining two buffers to pass in and out data:
unsigned char inputBuffer[100];
unsigned char outputBuffer[100];
But now it turns out I need the output buffer to be larger under
certain cases. What I wanted to do was make the output buffer double
size:
unsigned char outputBuffer[200];
And then use the input buffer as a portion of outputBuffer:
unsigned char *inputBuffer = outputBuffer + 100;
When necessary, the outputBuffer could then use the large array and
inputBuffer would have it's space as well, without having to allocate
the extra 100 bytes for the outputBuffer.
So I made this change, however, now input is not working. I would
have thought subscripting that was existing in code would still work.
My code all uses inputBuffer[location] as means of accessing the
inputBuffer.
So my question is, what am I doing wrong?
There's nothing inherently wrong with your pointer
arithmetic, if that's what's worrying you. Note, though,
that this doesn't magically create 100 extra bytes out
of thin air. What you're actually doing is sharing the
latter half of the 200-char buffer, using those locations
for input and for the tail end of long outputs. Are your
output characters stomping all over your inputs before
you've processed them? Are you, say, reading data into
inputBuffer, then filling outputBuffer with blanks, then
trying to process the suddenly all-blank inputBuffer?
Without having seen any code, that's about all the
guessing I can manage.
-- Er*********@sun .com
On Thu, 07 Jun 2007 13:25:19 -0400 (while OU was sucking), Eric Sosman
wrote:
>Ron Blancarte wrote On 06/07/07 13:08,:
>I was looking through the newsgroup FAQ for an answer to my question, but it doesn't appear to have one.
I am working with a system that has VERY limited memory. I was defining two buffers to pass in and out data:
unsigned char inputBuffer[100]; unsigned char outputBuffer[100];
But now it turns out I need the output buffer to be larger under certain cases. What I wanted to do was make the output buffer double size:
unsigned char outputBuffer[200];
And then use the input buffer as a portion of outputBuffer:
unsigned char *inputBuffer = outputBuffer + 100;
When necessary, the outputBuffer could then use the large array and inputBuffer would have it's space as well, without having to allocate the extra 100 bytes for the outputBuffer.
So I made this change, however, now input is not working. I would have thought subscripting that was existing in code would still work. My code all uses inputBuffer[location] as means of accessing the inputBuffer.
So my question is, what am I doing wrong?
There's nothing inherently wrong with your pointer arithmetic, if that's what's worrying you. Note, though, that this doesn't magically create 100 extra bytes out of thin air. What you're actually doing is sharing the latter half of the 200-char buffer, using those locations for input and for the tail end of long outputs. Are your output characters stomping all over your inputs before you've processed them? Are you, say, reading data into inputBuffer, then filling outputBuffer with blanks, then trying to process the suddenly all-blank inputBuffer?
Without having seen any code, that's about all the guessing I can manage.
Damn, I did leave out a paragraph on this.
So yea, I didn't magically create 100 bytes, I am just sharing that
back 100 under the special circumstances (which I won't mind if I
clobber the information in the input Buffer). Normal cases should not
be a problem
What problem that I am having is that it seems my functions which
worked with:
unsigned char inputBuffer[100];
unsigned char outputBuffer[100];
don't appear to be working with:
unsigned char inputBuffer[100];
unsigned char *inputBuffer = outputBuffer + 100;
These are functions which don't produce enough data to actually hit
the 100 byte limit.
For example:
void SPI_receive()
{
systat_7 = 0;
SPICON = 0x31;
SPI_COMM_SS = 0;
SPIDAT = 0;
while (ISPI == 0);
inputBuffer[spi_in] = SPIDAT;
++spi_in;
if(!(--spiSize)){
systat_3 = 1;
systat_1 = 0;
}
SPI_COMM_SS = 1;
}
void spi_getSize()
{
*((char*)&spiSi ze ) = inputBuffer[1];
*((char*)&spiSi ze+1) = inputBuffer[2];
}
void SPI_send()
{
systat_7 = 0;
SPICON = 0x31;
if(!systat_5){
SPI_COMM_SS = 0;
SPIDAT = outputBuffer[OB_out];
while (ISPI == 0);
if(!(--spiSize))
systat_5 = 1;
++OB_out;
ISPI = 0;
SPI_COMM_SS = 1;
}
else{
systat_1 = systat_3 = systat_5 = systat_6 = 0;
systat_4 = 1;
}
}
These appear to be my problem functions right now. What happens is
that you xfer 3 bytes of data over the SPI bus initially. Then you
call spi_getSize(), so you know how many characters are being sent.
Then you start to use SPI_receive() to pull data off the bus 1
character at a time and place it into the buffer. After some
processing is done, and then the response is sent back out across the
SPI bus via SPI_send.
spi_in and OB_out are just indices which allow me to traverse
character by character through the buffers. There is an out and in
indice for each buffer (spi_in/spi_out and OB_in/OB_out)
RonB
On Thu, 07 Jun 2007 13:39:39 -0500 (while OU was sucking), Ron
Blancarte wrote:
>On Thu, 07 Jun 2007 13:25:19 -0400 (while OU was sucking), Eric Sosman wrote:
>>Ron Blancarte wrote On 06/07/07 13:08,:
>>I was looking through the newsgroup FAQ for an answer to my question, but it doesn't appear to have one.
I am working with a system that has VERY limited memory. I was defining two buffers to pass in and out data:
unsigned char inputBuffer[100]; unsigned char outputBuffer[100];
But now it turns out I need the output buffer to be larger under certain cases. What I wanted to do was make the output buffer double size:
unsigned char outputBuffer[200];
And then use the input buffer as a portion of outputBuffer:
unsigned char *inputBuffer = outputBuffer + 100;
When necessary, the outputBuffer could then use the large array and inputBuffer would have it's space as well, without having to allocate the extra 100 bytes for the outputBuffer.
So I made this change, however, now input is not working. I would have thought subscripting that was existing in code would still work. My code all uses inputBuffer[location] as means of accessing the inputBuffer .
So my question is, what am I doing wrong?
There's nothing inherently wrong with your pointer arithmetic, if that's what's worrying you. Note, though, that this doesn't magically create 100 extra bytes out of thin air. What you're actually doing is sharing the latter half of the 200-char buffer, using those locations for input and for the tail end of long outputs. Are your output characters stomping all over your inputs before you've processed them? Are you, say, reading data into inputBuffer , then filling outputBuffer with blanks, then trying to process the suddenly all-blank inputBuffer?
Without having seen any code, that's about all the guessing I can manage.
Damn, I did leave out a paragraph on this.
So yea, I didn't magically create 100 bytes, I am just sharing that back 100 under the special circumstances (which I won't mind if I clobber the information in the input Buffer). Normal cases should not be a problem
What problem that I am having is that it seems my functions which worked with:
unsigned char inputBuffer[100]; unsigned char outputBuffer[100];
don't appear to be working with:
ONE THING!!
I don't know if this makes a difference or not, BUT...
I forgot to mention, inputBuffer and outputBuffer are both global.
They are being accessed via extern in the SPI routines. Will this
make any sort of differnce?
>unsigned char inputBuffer[100]; unsigned char *inputBuffer = outputBuffer + 100;
These are functions which don't produce enough data to actually hit the 100 byte limit.
For example:
void SPI_receive() { systat_7 = 0; SPICON = 0x31; SPI_COMM_SS = 0; SPIDAT = 0; while (ISPI == 0); inputBuffer[spi_in] = SPIDAT; ++spi_in; if(!(--spiSize)){ systat_3 = 1; systat_1 = 0; } SPI_COMM_SS = 1; }
void spi_getSize() { *((char*)&spiSi ze ) = inputBuffer[1]; *((char*)&spiSi ze+1) = inputBuffer[2]; }
void SPI_send() { systat_7 = 0; SPICON = 0x31; if(!systat_5){ SPI_COMM_SS = 0; SPIDAT = outputBuffer[OB_out]; while (ISPI == 0); if(!(--spiSize)) systat_5 = 1; ++OB_out; ISPI = 0; SPI_COMM_SS = 1; } else{ systat_1 = systat_3 = systat_5 = systat_6 = 0; systat_4 = 1; } }
These appear to be my problem functions right now. What happens is that you xfer 3 bytes of data over the SPI bus initially. Then you call spi_getSize(), so you know how many characters are being sent. Then you start to use SPI_receive() to pull data off the bus 1 character at a time and place it into the buffer. After some processing is done, and then the response is sent back out across the SPI bus via SPI_send.
spi_in and OB_out are just indices which allow me to traverse character by character through the buffers. There is an out and in indice for each buffer (spi_in/spi_out and OB_in/OB_out)
RonB
Ron Blancarte wrote On 06/07/07 14:39,:
[...]
What problem that I am having is that it seems my functions which
worked with:
unsigned char inputBuffer[100];
unsigned char outputBuffer[100];
don't appear to be working with:
unsigned char inputBuffer[100];
unsigned char *inputBuffer = outputBuffer + 100;
Of course this won't "work:" It won't even compile.
And if the first `inputBuffer' is really `outputBuffer',
then the buffer isn't big enough. We can sit here all
day trying to guess how to change what you've shown to
get to what your code is actually like, but in the end
that just means we're debugging our guesses and not
debugging your code.
If you feel ill, do you send your doctor a crayon
drawing of your body with an arrow saying "This is where
it hurts?"
If your car won't start, do you call the garage and
tell the mechanic "It's a sort of off-blue color, more
toward aqua. What's wrong with it?"
I'm not asking for you to post all umpty-bazillion
lines of your code (and I wouldn't read it if you did).
Whittle the code down to the smallest complete and
compilable program that demonstrates the problem, and
post that exact code: No paraphrases, no abbreviations,
no fill-in-the-blanks, but something another person can
run through his compiler unmodified. That way, we'll
be debugging your code instead of debugging a sort of
cloud of more and less likely possibilities centered
around your code.
Oh, and one more thing: "input is not working" is
not a sufficiently precise description of your problem.
In what way is it "not working?" What actually happens,
and how does that differ from what you hoped would happen?
Some people on this group seem to be able to read minds
on occasion, but it's not a reliable talent.
People *will* try to help you, but you've got to
cooperate more actively.
-- Er*********@sun .com
"Ron Blancarte" <ron@---TAKETHISOUT---.blancarte.comw rote in message
news:0v******** *************** *********@4ax.c om...
On Thu, 07 Jun 2007 13:39:39 -0500 (while OU was sucking), Ron
Blancarte wrote:
>>On Thu, 07 Jun 2007 13:25:19 -0400 (while OU was sucking), Eric Sosman wrote:
>>>Ron Blancarte wrote On 06/07/07 13:08,: I was looking through the newsgroup FAQ for an answer to my question, but it doesn't appear to have one.
I am working with a system that has VERY limited memory. I was defining two buffers to pass in and out data:
unsigned char inputBuffer[100]; unsigned char outputBuffer[100];
But now it turns out I need the output buffer to be larger under certain cases. What I wanted to do was make the output buffer double size:
unsigned char outputBuffer[200];
And then use the input buffer as a portion of outputBuffer:
unsigned char *inputBuffer = outputBuffer + 100;
When necessary, the outputBuffer could then use the large array and inputBuffe r would have it's space as well, without having to allocate the extra 100 bytes for the outputBuffer.
How do you tell the buffer's clients how large it is???? If you use
sizeof(outputBu ffer) you're going to have trouble.
karl m
On Thu, 07 Jun 2007 20:58:53 GMT (while OU was sucking), Karl Malbrain
wrote:
>"Ron Blancarte" <ron@---TAKETHISOUT---.blancarte.comw rote in message news:0v******* *************** **********@4ax. com...
>On Thu, 07 Jun 2007 13:39:39 -0500 (while OU was sucking), Ron Blancarte wrote:
>>>On Thu, 07 Jun 2007 13:25:19 -0400 (while OU was sucking), Eric Sosman wrote: Ron Blancarte wrote On 06/07/07 13:08,: I was looking through the newsgroup FAQ for an answer to my question, but it doesn't appear to have one. > I am working with a system that has VERY limited memory. I was defining two buffers to pass in and out data: > unsigned char inputBuffer[100]; unsigned char outputBuffer[100]; > But now it turns out I need the output buffer to be larger under certain cases. What I wanted to do was make the output buffer double size: > unsigned char outputBuffer[200]; > And then use the input buffer as a portion of outputBuffer: > unsigned char *inputBuffer = outputBuffer + 100; > When necessary, the outputBuffer could then use the large array and inputBuff er would have it's space as well, without having to allocate the extra 100 bytes for the outputBuffer.
How do you tell the buffer's clients how large it is???? If you use sizeof(outputB uffer) you're going to have trouble.
Yea, that I know. when defining the buffers, instead of using "100"
etc, they are constant defines. If the size needs to be checked, then
I will just check it against these define statesments.
RonB
On Thu, 07 Jun 2007 16:26:16 -0400 (while OU was sucking), Eric Sosman
wrote:
>Ron Blancarte wrote On 06/07/07 14:39,:
>[...] What problem that I am having is that it seems my functions which worked with:
unsigned char inputBuffer[100]; unsigned char outputBuffer[100];
don't appear to be working with:
unsigned char inputBuffer[100]; unsigned char *inputBuffer = outputBuffer + 100;
Of course this won't "work:" It won't even compile. And if the first `inputBuffer' is really `outputBuffer', then the buffer isn't big enough. We can sit here all day trying to guess how to change what you've shown to get to what your code is actually like, but in the end that just means we're debugging our guesses and not debugging your code.
That would be a typo as you pointed out.
unsigned char outputBuffer[200];
unsigned char *inputBuffer = outputBuffer + 100;
I'm not asking for you to post all umpty-bazillion lines of your code (and I wouldn't read it if you did). Whittle the code down to the smallest complete and compilable program that demonstrates the problem, and post that exact code: No paraphrases, no abbreviations, no fill-in-the-blanks, but something another person can run through his compiler unmodified. That way, we'll be debugging your code instead of debugging a sort of cloud of more and less likely possibilities centered around your code.
If possible I would do this. Unfortunately what I am looking at here
is a 10000 line program that I need to change the memory footprint of
to add a new feature. The code runs in an in-house developed hardware
environment w/ two 8051 processors, to "Whittle the code down" would
still result in a large program.
I posted some function which utilize this code, mainly asking if,
syntactically they are correct. Clearly, I agree, my typo in the
above code was wrong, but in the thread of whittling down the code,
here it goes:
Given these declarations:
unsigned char inputBuffer[100];
unsigned char outputBuffer[100];
int spiSize;
And this function:
void spi_getSize()
{
*((char*)&spiSi ze ) = inputBuffer[1];
*((char*)&spiSi ze+1) = inputBuffer[2];
}
if I changed my declarations to this:
unsigned char outputBuffer[200];
unsigned char *inputBuffer = outputBuffer + 100;
int spiSize;
Ignoring reading in data (which again was done via the SPI_receive
routine I posted earlier), should the spi_getSize function continue to
work as expected? (Which is reading in the 2nd and 3rd characters of
inputBuffer into an int).
RonB
Ron Blancarte wrote:
>
.... snip ...
>
ONE THING!!
I don't know if this makes a difference or not, BUT...
I forgot to mention, inputBuffer and outputBuffer are both global.
They are being accessed via extern in the SPI routines. Will this
make any sort of differnce?
Please snip immaterial quoted material.
The answer is quite likely yes. They will affect anything such as
"sizeof buffer".
--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com
Ron Blancarte wrote:
>
.... snip ...
>
And then use the input buffer as a portion of outputBuffer:
unsigned char *inputBuffer = outputBuffer + 100;
When necessary, the outputBuffer could then use the large array
and inputBuffer would have it's space as well, without having to
allocate the extra 100 bytes for the outputBuffer.
So I made this change, however, now input is not working. I
would have thought subscripting that was existing in code would
still work. My code all uses inputBuffer[location] as means of
accessing the inputBuffer.
So my question is, what am I doing wrong?
Who knows. You omitted the code. Cut your system down to
something compilable and executable that exhibits the problems
(about 100 lines or so) and post that. By then you probably have
solved it yourself.
--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Roland Hall |
last post by:
Is there a way to return multiple values from a function without using an
array? Would a dictionary object work better?
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -...
|
by: Joshua Neuheisel |
last post by:
The following code compiles with gcc 3.2.2 and Visual C++ 6:
#include <stdio.h>
int main()
{
int a = {3, 4};
printf ("%d\n", 0);
return 0;
}
|
by: a.zeevi |
last post by:
free() multiple allocation error in C
====================================
Hi!
I have written a program in C on PC with Windows 2000 in a Visual C
environment.
I have an error in freeing multiple allocation as follows:
1. I allocated an array of pointer.
2. I Read line by line from a text file.
3. I allocated memory for the read line.
|
by: toton |
last post by:
Hi,
I am looking for a circular buffer solution ( a fixed buffer) , where
the elements can be pushed back & removed front. It looks stl deque
can be a solution. my question is,
1) circular buffer is random access? (i.e implemented over array and
not linked list)
2) if I reserve the required space & do push_back & remove_front so
that total memory doesn't exceed the reserved amount, will the internal
pointers will wrap, or the memory...
|
by: Shhnwz.a |
last post by:
Hi,
I am in confusion regarding jargons.
When it is technically correct to say.. String or Character Array.in c.
just give me your perspectives in this issue.
Thanx in Advance.
| |
by: Zhou Yan |
last post by:
I want to define a pointer to a multiple-subscripted array.
For instance, I have an array defined as below( I have reduced the
size of the array as well as the dimension, but I think it OK to ask
this simple case.)
/----
int array = { 1, 2, 3, 4 }
\-----
|
by: Memphis Steve |
last post by:
Is it possible to combine multiple javascipts into one file and then call that file from a linked URL in the head section of an XHTML file?
Here are the two scripts I want to use with the instructions on where to normally place them in an XHTML document:
SCRIPT #1:
Step 1: Insert the below anywhere into the <body> section of your page where you wish the clock to be displayed:<script>
/*
Live Date Script-
|
by: Neil |
last post by:
"lyle" <lyle.fairfield@gmail.comwrote in message
news:48c3dde7-07bd-48b8-91c3-e157b703f92b@f3g2000hsg.googlegroups.com...
Question for you. I'm doing something similar, only, instead of opening the
forms all at once, I'm opening them as needed. I have a main form with
multiple records; and then I have a pop-up form that the user opens with
button. The pop-up form contains one record relating to the current record
in the main form (but...
|
by: ctj951 |
last post by:
I have a very specific question about a language issue that I was
hoping to get an answer to. If you allocate a structure that
contains
an array as a local variable inside a function and return that
structure, is this valid?
As shown in the code below I am allocating the structure in the
function and then returning the structure. I know if the structure
contained only simple types (int, float) this will work without
problems as you...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |