string size greater than page size?

L

lazy

wat will happen to a std string function like strcmp etc when the size
of the string is greater than page size of the OS?
A bigger question is how will they be even stored? (if at all they can
be stored)
My guess is that this is not an issue as I assume we can malloc like
1MB(>page size), so when we try to access it,
both the pages are brought to memory. Does malloc by default tries to
allocate in the same page? If so, how will it deal with fragmentation?

Pardon me if the question doesnt make sense.
 
C

christian.bau

wat will happen to a std string function like strcmp etc when the size
of the string is greater than page size of the OS?
A bigger question is how will they be even stored? (if at all they can
be stored)
My guess is that this is not an issue as I assume we can malloc like
1MB(>page size), so when we try to access it,
both the pages are brought to memory. Does malloc by default tries to
allocate in the same page? If so, how will it deal with fragmentation?

Pardon me if the question doesnt make sense.

The standard library functions always behave the way it is described
in the C Standard.
 
C

Chris Dollin

lazy said:
wat will happen to a std string function like strcmp etc when the size
of the string is greater than page size of the OS?

Nothing. The standard functions needn't care -- or even know -- about
things like "the page size of the OS".
A bigger question is how will they be even stored?

As a sequence of bytes.
My guess is that this is not an issue as I assume we can malloc like
1MB(>page size),

How much space one can malloc depends on the underlying implementation.
It is, however, unlikely that malloc would restrict itself to space
less than the "page size". Why should it?
so when we try to access it,
both the pages are brought to memory. Does malloc by default tries to
allocate in the same page? If so, how will it deal with fragmentation?

It doesn't have to do anything, in general. OS's that have "page sizes"
tend to go to a great deal of trouble to arrange that programs running
under them don't need to know about them: that is rather the point about
memory mapping, after all.
 
A

Army1987

lazy said:
wat will happen to a std string function like strcmp etc when the size
of the string is greater than page size of the OS?
A bigger question is how will they be even stored? (if at all they can
be stored)
My guess is that this is not an issue as I assume we can malloc like
1MB(>page size), so when we try to access it,
both the pages are brought to memory. Does malloc by default tries to
allocate in the same page? If so, how will it deal with fragmentation?

Pardon me if the question doesnt make sense.

You can't know (as far as the C programming language is concerned),
and you shouldn't care. If the malloc returns a non-null pointer,
you can use as many bytes from there on as you asked it to
allocate. You don't need to know where they are.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top