Sponsored Content
Top Forums Programming C: inputting string of unknown length Post 303041036 by jim mcnamara on Tuesday 12th of November 2019 03:18:25 PM
Old 11-12-2019
The problem relates to memory management. The OS sets an "end point" and a "start point" for a process working set (memory) when the process begins.

There are flavors of the malloc (also realloc) routine, many based on Doug Lea's original malloc. His version calls brk() when it thinks more added memory will go beyond the bounds of the current memory. This brk() call will possibly change the end point of the process only when your malloc asks for more and it bumps heads with the end of the data segment or existing stack. So your string start and end may be moved

The size [executable name goes here] command shows what is going on.

Tutorial with great examples:

Memory Layout of C Programs - GeeksforGeeks
This User Gave Thanks to jim mcnamara For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Selecting unknown string.

Work problem: Need to set up a job to periodically check that the number of entries in the mail queue. I'm able to do the following: mailq | grep "Mail Queue" Which returns: Mail Queue (7 requests) Unfortunately I'm not sure how I select between `(` and `requests`? ... (2 Replies)
Discussion started by: Cameron
2 Replies

2. UNIX for Dummies Questions & Answers

length of the string

Hi all, pls help me in finding the length of the given string, do we need to write a code seperately or is there any command?? pls help. (3 Replies)
Discussion started by: vasikaran
3 Replies

3. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies

4. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies

5. Shell Programming and Scripting

perl newbie: how to extract an unknown word from a string

hi, im quite new to perl regexp. i have a problem where i want to extract a word from a given string. but the word is unknown, only fact is that it appears as the second word in the string. Eg. input string(s) : char var1 = 'A'; int var2 = 10; char *ptr; and what i want to do is... (3 Replies)
Discussion started by: wolwy_pete
3 Replies

6. Shell Programming and Scripting

searching and storing unknown number of lines based on the string with a condition

Dear friends, Please help me to resolve the problem below, I have a file with following content: date of file creation : 12 feb 2007 ==================== = name : suresh = city :mumbai #this is a blank line = date : 1st Nov 2005 ==================== few lines of some text this... (7 Replies)
Discussion started by: swamymns
7 Replies

7. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

8. UNIX for Dummies Questions & Answers

Extract substring of unknown length from string

I have a string: hgLogOutput=" +0000 files: forum/web/hook-test.txt /forum/web/hook-test-2.txt description: test" and I want to extract the file names from it, they will always appear between the files: and the description:. I have worked out that I can do this: "$hgLogOutput" | awk '{... (2 Replies)
Discussion started by: klogger
2 Replies

9. Shell Programming and Scripting

Delimted to padded conversion with unknown field length

I’m looking for an elegant way to convert a delimited file (comma delimited in this case) to padded columns (for printing in non-proportional font) but the length of each column is not known ahead of time. It needs to be calculated for each column from the longest entry in that column in a given... (3 Replies)
Discussion started by: Michael Stora
3 Replies

10. Shell Programming and Scripting

Removing characters from end of line (length unknown)

Hi I have a file which contains wrong XML, There are some garbage characters at the end of line that I want to get rid of. Example: <request type="product" ><attributes><pair><name>q</name><value><!]></value></pair><pair><name>start</name><value>1</value></pair></attributes></request>�J ... (7 Replies)
Discussion started by: dirtyd0ggy
7 Replies
BRK(2)							     Linux Programmer's Manual							    BRK(2)

NAME
brk, sbrk - change data segment size SYNOPSIS
#include <unistd.h> int brk(void *addr); void *sbrk(intptr_t increment); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): brk(), sbrk(): Since glibc 2.19: _DEFAULT_SOURCE || (_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200112L) From glibc 2.12 to 2.19: _BSD_SOURCE || _SVID_SOURCE || (_XOPEN_SOURCE >= 500) && ! (_POSIX_C_SOURCE >= 200112L) Before glibc 2.12: _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500 DESCRIPTION
brk() and sbrk() change the location of the program break, which defines the end of the process's data segment (i.e., the program break is the first location after the end of the uninitialized data segment). Increasing the program break has the effect of allocating memory to the process; decreasing the break deallocates memory. brk() sets the end of the data segment to the value specified by addr, when that value is reasonable, the system has enough memory, and the process does not exceed its maximum data size (see setrlimit(2)). sbrk() increments the program's data space by increment bytes. Calling sbrk() with an increment of 0 can be used to find the current loca- tion of the program break. RETURN VALUE
On success, brk() returns zero. On error, -1 is returned, and errno is set to ENOMEM. On success, sbrk() returns the previous program break. (If the break was increased, then this value is a pointer to the start of the newly allocated memory). On error, (void *) -1 is returned, and errno is set to ENOMEM. CONFORMING TO
4.3BSD; SUSv1, marked LEGACY in SUSv2, removed in POSIX.1-2001. NOTES
Avoid using brk() and sbrk(): the malloc(3) memory allocation package is the portable and comfortable way of allocating memory. Various systems use various types for the argument of sbrk(). Common are int, ssize_t, ptrdiff_t, intptr_t. C library/kernel differences The return value described above for brk() is the behavior provided by the glibc wrapper function for the Linux brk() system call. (On most other implementations, the return value from brk() is the same; this return value was also specified in SUSv2.) However, the actual Linux system call returns the new program break on success. On failure, the system call returns the current break. The glibc wrapper function does some work (i.e., checks whether the new break is less than addr) to provide the 0 and -1 return values described above. On Linux, sbrk() is implemented as a library function that uses the brk() system call, and does some internal bookkeeping so that it can return the old break value. SEE ALSO
execve(2), getrlimit(2), end(3), malloc(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2016-03-15 BRK(2)
All times are GMT -4. The time now is 02:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy