Can you define an array on the stack and pass the pointer to a global variable?

The Original Question

I’m programming C on a microchip that doesn’t support any memory allocation commands, but it does like pointers (of course). So my question is:

Is there a way to define an array within a function, and pass the pointer to that array back to a global variable?

This would be a way to have a dynamic memory use WITHOUT malloc, realloc, or calloc. Essentially stack memory being passed back to global WITHOUT it destroying itself. I’m assuming that the alloc commands are specifically needed to ensure it doesn’t get destroyed, but I wanted to check and see if there was a way around this.

My Answer

The main problem is function calls and how calls affect stack. On IBM architecture, simply, current EBP pushed to stack, caller stack frame is saved to EBP and callee parameters pushed to stack(generally). On return pushed EBP is poped and stack allocated parameters could be overwritten by caller, that area is free to use since callee is returned.

When you some how dynamically allocate some space on stack, it’s a possibility to overwrite that space somewhere in time at a function call which has some wide veriaty of parameters or recursive calls. This is why all dynamic allocations happens in Heap and heap management is at the hands of operating system. Since malloc (etc) is o.s. wrappers for heap allocations you do not need to worry about that management, o.s. will take it care for you.

If you want to achieve dynamic allocations on stack you need to go with assembly. Make sure allocate enough space before a function call at the caller site and take that space back when caller will be returned to its caller. And that organisation would be a brainfk i guess..

The Link on StackExchange Stackoverflow Site

String İçindeki Bir Alt String’i Kırpmak

Stackoverflow sitesinde rastladığım bir soru var. Kişi bir string verisi içindeki herhangi bir karakteri ya da alt string i nasıl kırpabileceğini sormuş. Topluluktaki bazı kişilerle ufak-tefek çatışmalar, tartışmalar olsa da istenilen işlemi genelleştirilmiş bir şekilde şu şekilde gerçekleştirebilirsiniz:
Continue reading

Is it best to reformat the hard drive to exFAT using 512kb chunk, or smaller or bigger chunks?

I can reformat a brand new 2TB WD Passport drive to exFAT, with choice of many “Allocation Unit Size”:

128kb 256kb 512kb 1024kb 4096kb 16384kb 32768kb


which one is best if this drive is mainly used for recording HDTV programs using Media Center on Windows 7? thanks.

Answer:

You should first understand what “Allocation Unit Size” means.

It is the smallest data block on the disk. Your actual data will be seperated to those units while saving to the disk. For example, if you have a file sized 512KB and you have 128KB allocation unit size, your file will be saved in 4 units in the disk (512KB/128KB). If your file’s size is 500KB and you have 128KB A.U.S, your file still be saved in 4 units in the disk because as mentioned above 128KB is the smallest size of an allocation unit (384KB will be allocated in 3 units and remaining 116KB will be allocated in another unit. You can observe this behaviour on file properties screen on Windows, what is your file size and how much space this file actually covers on the disk). And the operating system reads only that A.U.Sd much data at a low level disk read operation.

Those being said, using large A.U.S significantly reduces the free space utilization due to not using the last allocation unit completely. And as a side effect, the number of files to store on the disk is reduces due to same problem, last a.u not being used fully. But, here’s the trade-off, using A.U.S, significantly again, improves the disk reading performance. The O.S can read more data at one read. Imagine, O.S makes couple of disk reads to completely read a GB sized file!..

Using small A.U.S improves the free space utilization but reduces the disk read performance. Think using large A.U.S in reverse, same category problems and improvements, but in reverse…

So, what is the conclusion here? If you will store large, I mean “large!”, files on the disk, higher A.U.S will give you appreciable read performance while reducing the file count and free space…

Which A.U.S you should use? This depends on how much your average file size is. Also you can compute the free space utilization accourding to your file sizes.

Very lucid breakdown. But does each cluster have any inherent storage overhead (e.g. indices or the cluster equivalent of sector headers)? And are there any interactions with physical/emulated sector sizes or cache sizes? Lastly, do larger cluster sizes negatively affect random access performance? 4KB sector HDDs seem to have lower random access performance even though they have higher throughput than 512byte HDDs.

There are no significant storage overhead at high levels. Besides there is enough hrdw overhead since the actual physical sector size is 512Bytes… There is a part of file system formatting that records the cluster information, from how many sector this cluster is created, to the partition structure. The sector size emulation is a job of disk driver. O.S. file system server should deal with logical organization (NTFS, FAT etc) at high level O.S ops, smallest unit reads/writes at low level O.S ops and disk driver itself must work back to back with controller(hardware) for low level hardware access which contains the emulation. And caching is not a job of O.S. It is done by hardware itself. O.S asks for certain data, disk decides wheter look on cache or platter itself for it… Random access performance should actually not be a general performance criteria when having parameters like A.U.S.. Think it this way:

N sized units, M number units, N*M capacity disk, “what is the probability of hitting this unit?” and remember, disk has to be more precise in locating the beginnings of the units.. So, Random access performance is something bound with M^2/N.. 4K units, 8 units, 32K capacity disk. R.A bound with 64/4. 8K units, 4 units, same capacity, same disk. R.A becomes 16/8. You wouldn’t find an article about this kind of calculation, but believe me :) It is more job to “randomly” locate a data using large unit sizes over small sizes.

Soru: Slow LAN transfer from 3rd party computer

Hi Everyone,

I’ve got an odd problem that I’m not really sure where to start the troubleshooting process.

I have a ‘server’ with Windows Server 2008R2 (64-bit) installed and it has a couple of hard drives. If I Remote Desktop into the server and transfer files from one HD to the other, all it fine.

If however, I use my workstation (Windows 7 64bit) and open up a shared resource on the server and transfer a file from one hard drive on the server to another HD on the server (not using Remote Desktop, just Windows explorer/Network places), the transfer crawls… It takes about 5mins to discover files/calculate the transfer and then starts transferring at speeds like 56KB/s – 200KB/s.

Both machines have Marvel GigE network ports with a TrendNet 8-port green GigE switch. I’ve set Jumbo packets to 9K on both machines…

 

Cevap:

Disk to disk copies on the same machine are not impacted by the same service overhead, or network considerations, as network copies. It’s even faster if the disks are two physically different disks, rather than 2 partitions.

That being said, I’ve seen several complaints about Vista and 7 with network copying. One of the recommendations from a Microsoft tech (cannot remember the source) is to disable the autotuninglevel. This can be done from a command prompt.

  • Click start, in the run/search box, type cmd, and hit CTRL+SHIFT+ENTER (this is needed if you have UAC enabled).
  • In the prompt that opens, type netsh int tcp set global autotuninglevel=disabled
  • Restart your computer.

If that doesn’t help, you can turn back the options by changing disabled to normal and restarting again.

As a side note, when copying from driveA to driveB on the same server, but via a network share, the data has to stream to the client, then back to the server. This is essentially doubling the actual amount of data being transferred.

Network copy also adds TCP/IP overhead as every TCP packet will carry 32byte header. So actual processed data, not just copied, will be twice as data itself plus significant amount of networking overhead.

Problem getting into our website from within the network

Hi…

we have a domain and it is the same network domain. if i try the website with “www” it will work and go to the iis server xxx.xxx.xxx.174 but without the “www” it will go to the xxx.xxx.xxx.175 (the active directory and dns of the network) and becuase that there is no iis website set on it it will show iis under construction error.

what can we do?

 

The answer:

First mistake is naming your outgoing domain same as internal domain. You can simply make them seperate ;) Like outgoing: something.com and internal: something.pvt or something.com.local. Just differ your name ;)

Second mistake is using AD’s DNS as your outgoing DNS… Always use another configured DNS server which faces the internet, and to achieve that you should name your domains differently ;) And configure that outsider DNS to relay internal queries to AD’s DNS… ( redirect x.y.local to IP(a.b.c.d) )

About the problem, x.y is your ACTUAL DOMAIN, so any query asks for x.y domain, always {should} go(es) to your AD’s DNS, and because of the AD behaviour, it will resolve to the address of DC and you’ll get that DC’s IP adress ;) ( this will be more and more annoying when you have multiple DCs, because there’s a very good chance to get different IPs {which will be that DCs ;) } ) And there it comes the 3rd mistake: Entering a host record “www” to DC’s DNS that faces to outside… When a www.x.y query comes, DC’s DNS will resolve that corretly, but, IT IS your DC! Your hearth, your center point! ( this is connected to second mistake i mentioned above ) And of course, semanticly, you’ll want to query x.y to get your web server but no, what will return to you is your DC…

About the solution, you’ll have to configure the IIS on that DC and redirect your default site to your actual web server ( www.x.y ) ( like “gravyface” explained ) unless you dont want to deploy a second DNS server to your network to achieve this Front-end Back-end acrhitecture..

How to achieve this WiFi setup in the cheapest way ?

I’m setting up a WiFi network for a small NGO here in Bolivia, so it means we are trying to do it on the tightest budget possible.

The site comprises 2 buildings about 100 meters apart from each other. We want to have one WiFi access point in the main house, connected to the router which is connected to internet. This AP will be used for the computers inside this house.

Then we want to have a second AP in the second house, acting as a repeater (looks like WDS – Wireless Distribution System is the way to go here.) The antennas of both devices would be put outside the window with a direct line of sight between them.

Finally we want to have both wireless AND ethernet clients to connect to the second access point, and access internet via the first AP.

So the question is : is this achievable with common consumer WiFi Access Points/Routers ? Or is some more specific hardware required ? Keeping in mind that money is not flowing here and we would rather spend it on schoolbooks or medicine than expensive hardware ;)

 

The Answer:

Yes, it is possible.. But there is a trade off, as always have been, the cheaper hardware you purchase smaller coverage you get, according to hardware’s antenna and signaling quality…

Basic network architecture would be like this:

Internet – Gateway(main router) – [{if that router doesnt have enough ports}Switch – ]Clients (so 1st AP will be a client here ;)).. .. .. 2nd AP (as a repeater)- Switch – Ethernet Clients (at second place)

So actually there is no need a special hardware but specific ;) And you also need to configure this architecture very carefully. Unless you dont, there is a biiig possibility that you both users (as ‘place 1’ and ‘place 2’ ) will be unable to communicate ;)

SORU : Delphi ile PC’nin Sesini Kontrol Etme

Herkese merhabalar öncelikle… Bilgisayarın sesini açıp kısabilen bir program hakkında yardımlarınıza ihtiyacım var arkadaşlar.VB’de rahatlıkla bulup kullanabildiğim bu kodları, Delphi’de bulamıyorum.Basit olarak PC’nin sesini açabilip kısabileceğimiz programın kodlarına ihtiyacım var.Şimdiden sağolun… Allah’a emanet olun…

Continue reading

SORU : facebook daki videoları delphi ile nasıl indirebilirim

buna benzer konu açıldı demeyin bana çünki hepsini denedim, eğer dosya adresi tam varsa indirio mesala ‘www.asjdhsaj.com/aaa.exe’ böyle olunca indirio facedeki video linkleri farklı mesala ‘http://www.facebook.com/ajax/share_dialog.php?s=99&appid=2309869772&p[]=726372257&p[]=166297353402532&action_link=share’ şu videoyu nasıl indirebilirim teşekkürler şimdiden

Continue reading

SORU : string içinde ansichar okuma

Bir string’im var ve x;y;z formatında,
Tstringist’e tokenizer ile keserek ekliyorum.Tstringist elemanlarından biri “ karakterini içeriyor.Bu karakteri ord() fonksiyonu ile çağırdığımda fakrlı sonuc alıyorum.
Aşağıda örnekği mevcut.Delphi 2009 kullanıyorum.
Yardımcı olabilirmisniz.

var
sAnsiChar:ansichar;
sstring:string;
begin

sstring:=’“’;
sAnsiChar:=’“’;
showmessage(inttostr(ord(sstring[1])));//4971196 donuyor(hatalı)
showmessage(inttostr(ord(sAnsiChar)));//147 donuyor(doğru)

end;

Continue reading